Table 10-1 lists the top 20 rock-solid performance development considerations this chapter covers.
|
Consideration |
Targeted
|
|---|---|
|
Avoid constant use of large session objects |
Web tier |
|
Invalidate HTTP sessions when they aren't required |
Web tier |
|
Use the init() servlet method if doGet() and doPost() aren't required |
Web tier |
|
Use
<jsp:
|
Web tier |
|
Don't use the single-threaded model with servlets |
Web tier |
|
Reuse EJB
|
Business tier |
|
Consider Pass-by-Reference rather than Pass-by-Value |
Business tier |
|
Use a multithreaded logger instead of system.out.println() |
Business tier |
|
Use container threading services and avoid manually spawning threads |
Business tier |
|
Avoid lazy initialization of objects |
Business tier |
|
Avoid overusing Java niceties |
Business tier |
|
Avoid stateful EJBs where possible |
Business tier |
|
Use constants |
Business tier |
|
Assume remote objects, but write for local |
Business tier |
|
Use Abstraction |
Business tier |
|
Use WebSphere data sources |
Data tier |
|
Release JDBC resources when you've finished with them |
Data tier |
|
Use container-managed persistence only for high-read database access |
Data tier |
|
Use Data Access Objects for general database access |
Data tier |
|
Use prepared SQL statements where possible |
Data tier |
Let's now take a look at each consideration in more detail. Considerations appear under the appropriate tier.
The
Web tier
refers to all Web containers, Web servers, and components. This includes Java
JavaServer Pages (JSP) pages
Servlets
Standard classes and beans
Session Manager settings
As you've learned in previous chapters, sessions are a key element of any Web-based WebSphere application environment. It's possible to overuse sessions by filling them up with unnecessary information, not releasing unwanted elements after use, or using them for incorrect purposes. The effect is exaggerated when session persistence is used to achieve additional levels of redundancy.
Essentially, in the case of
To summarize,
Don't use sessions for storing large amounts of data for all users.
Try to keep session object sizes at around 4KB for 95 percent of all session objects. This allows for some large sessions, which may be required to store specific data (e.g., 100KB of data to store an uploaded text file).
Don't load everything into a session object. Only load the specific information you need in your session at any one time. Too often I've seen situations in which environments load large amounts of data into session objects, only to need very specific amounts of data.
Consider using a database to store information specific to
|
Performance and scalability benefit: |
1 |
|
Implementation complexity: |
3 |
HTTP sessions are often used in Web applications. One of the common implementation errors that developers make is not cleaning up sessions that are no longer required. This is a side effect of the thought that because you don't need to manage memory in Java (unlike in C, C++, and so on), you don't need to clear off unused objects.
Because WebSphere can maintain only a certain number of sessions at any one time in memory (a configurable counter), and the fact that there's a finite amount of memory available per application Java Virtual Machine (JVM), you'll want to ensure that you provide your JVM and other application threads the maximum amount of memory available or required by them. By also not
To summarize,
Ensure that your users are provided with a "log off" function that calls the invalidate() method.
Carefully model your users' online and pause times. You maybe able to decrease the period until WebSphere times out and ultimately forces all timed-out sessions to be invalidated. The default WebSphere setting is 30 minutes (1,800 seconds).
|
Performance and scalability benefit: |
3 |
|
Implementation complexity: |
2 |
Basic servlets consist of the
init()
,
doGet()
, and
doPost()
Quite often, a servlet isn't required to perform any function based on input. For this reason, there's no need to use a doGet() method call ”this will incur overhead that isn't required. Consider placing heavy or expensive transactions in the init() method instead of in the doGet() and doPost() methods. A classic example is to place bindings to data sources in the init() method, which will alleviate a rebind on each doGet() or doPost() method call. This will increase performance within your application.
To summarize, question the use of doGet() and doPost() method usage in servlets if the servlets aren't expecting any input but are required to return information.
|
Performance and scalability benefit: |
3 |
|
Implementation complexity: |
2 |
This JSP tag allows developers to directly call a JavaBean from within the JSP code. Quite often, developers use this approach in JSP pages to fill small
This tag, however, will create a new instance of the specific JavaBean if the JavaBean object doesn't already exist. Creating the new bean is an expensive JVM operation and, unless required, it should be used only to obtain a reference to an existing Java object.
|
Performance and scalability benefit: |
3 |
|
Implementation complexity: |
2 |
A design approach exists with servlets that allows the servlets to be developed using a single-threaded model. This approach is sometimes used to ensure the protection of specific variables within a servlet's context; however, it does introduce a performance and scalability
If specific variables need to be managed per client thread, consider using the session object for small variables or other forms of data storage, such as memory caches and/or databases.
|
Performance and scalability benefit: |
2 |
|
Implementation complexity: |
2 |