Skip Headers
Oracle® Containers for J2EE Servlet Developer's Guide
10g Release 3 (10.1.3)
B14426-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

8 Best Practices and Performance

This chapter provides programming tips for how to maximize the efficiency and performance of your servlets—general suggestions as well as suggestions regarding sessions, security, and thread models. There is also an introduction to the Oracle Dynamic Monitoring Service (DMS) to monitor performance. The following topics are covered:

Best Practices for Sessions

This section discusses considerations when using sessions:

See the Oracle Containers for J2EE Developer's Guide for information about clustering in OC4J.

Best Practices for Security

The following are considerations for the security of your Web application running in the OC4J servlet container:

For additional information, also see the reference documentation under "Elements and Attributes of orion-web.xml, global-web-application.xml".

Considerations for Thread Models

For a servlet in a nondistributable environment, a servlet container uses only one servlet instance for each servlet declaration. In a distributable environment, a container uses one servlet instance for each servlet declaration in each JVM. Therefore, a servlet container, including the OC4J servlet container, generally processes concurrent requests to a servlet by using multiple threads for multiple concurrent executions of the central service() method of the servlet.

Servlet developers must keep this in mind, making provisions for simultaneous processing through multiple threads and designing their servlets so that access to shared resources is somehow synchronized or coordinated. Shared resources fall into two main areas:

One option is to synchronize the service() method as a whole; however, this may adversely affect performance.

A better approach is to selectively protect instance or class fields, or access to external resources, through synchronization blocks.

As perhaps a last resort, the servlet specification supports a single-thread model. If a servlet implements the javax.servlet.SingleThreadModel interface, the servlet container must guarantee that there is never more than one request thread at a time in the service() method of any instance of the servlet. OC4J typically accomplishes this by creating a pool of servlet instances, with a separate instance handling each concurrent request. This process has significant performance impact on the servlet container, however, and should be avoided if at all possible. Furthermore, the SingleThreadModel interface will be deprecated in version 2.4 of the servlet specification.

For general information about multithreading, see the Sun Microsystems Java Tutorial on Multithreaded Programming at the following Web site:

http://java.sun.com/docs/books/tutorial/essential/threads/multithreaded.html

Best Practices for Performance

This section summarizes issues, mostly documented elsewhere in this manual, that may impact performance:

For further information, also see the reference documentation under "Elements and Attributes of orion-web.xml, global-web-application.xml".

Monitoring Performance

This section includes information about monitoring the performance of servlets.

Oracle Application Server Dynamic Monitoring Service

In an Oracle Application Server environment, the Dynamic Monitoring Service (DMS) adds performance-monitoring features to several components, including OC4J. The goal of DMS is to provide information about runtime behavior through built-in performance measurements so that users can diagnose, analyze, and debug any performance problems. DMS provides this information in a package that can be used at any time, including during live deployment. Data are published through HTTP and can be viewed with a browser.

Standard configuration for DMS modules is reflected in the OC4J system-application.xml file and the default-web-site.xml file. In system-application.xml, the Web module dms and the path to its WAR file is specified. The default-web-site.xml file specifies that this Web module is deployed to the OC4J default application and binds it to its context path. Do not directly alter any of these DMS configurations.

Use Application Server Control to access DMS, display DMS information, and, if appropriate, alter DMS configuration.

Refer to the Oracle Application Server Performance Guide for information about DMS, the Oracle Containers for J2EE Developer's Guide for information about the global application.xml file (which uses the same specification as the orion-application.xml file), and the Oracle Containers for J2EE Configuration and Administration Guide for information about Web site XML files.