Wednesday, August 10, 2011

J2EE Concurrency

A number of approaches are available for concurrency in J2EE applications, but each has its shortcomings:

  • Explicit allocation of threads is discouraged by the J2EE specifications since containers handle thread management. Having a thread pool ThreadPoolExecutor.
  • Using the Work Manager specification results in non-portable solutions that are limited to certain application servers, such as WebLogic and WebSphere, because it is not part of the J2EE specifications (including Java EE 5).
  • Encapsulating the work units in JMS queue messages that are then processed by Message Driven Beans (MDBs) in a concurrent fashion is appropriate for certain scenarios. However, this approach is relatively complex and resource-intensive for most applications.
  • Using inherent thread pool management of EJB timers. This approach is portable across application servers and does not require a messaging provider and resources such as queues and connection factories. Furthermore, since EJB timers are transactional and recoverable, this approach enables robust and reliable concurrency solutions

Tuesday, August 9, 2011

Use of finally block in Java

Problem statement: We noticed in Production that not all orders have entries in Audit tables.
We are calling audit in the finally() block for each process order call since all success and failure orders should be audited.

Fair point, is finally() block is called every time? yes, JVM spec says it is called. See patterns of calling in this post.

However there are do & don'ts -- see this. Where it says problems with exceptions & use of return statements in finally block. Nothing of this sort is seen in our code.

Then what could be the root cause?