Thread-safety features

Since EJB Server is a multithreaded environment, component instances that share resources and volatile data must be coded or configured to avoid problems with inconsistent state. For example, if all instances of a component write to the same file, you must take steps to ensure that the file is “locked” before each instance writes to it and “unlocked” when the write completes. If writes to the file are allowed to occur simultaneously, then output from two component instances may be mixed together within the file.

Whenever possible, avoid the use of static class variables. Also, avoid sharing stateful (being able to maintain information about the state of a resource) resources such as database connections or file descriptors. In cases where data and resources are shared, there are two ways to ensure thread safety in a component: