Friday, April 3, 2009

EJB 3 Slight Perfomance Increasing tips

Most of the people who code EJB 3 which i have seen so far are reluctant to override the defaults provided by the container. Specially when it comes to transactions handling. In EJB 3 a session bean's method's default transaction type is REQUIRED. So we keep this as it is in most cases and sometimes just use REQUIRES_NEW if we want to do a batch process withouth haulting the current transaction.
 
But what most of us forget is that methods such as find(),getReference() and flush() do not need a transaction in order to perform the required function. By keeping the container defaults you are unnecessarily burning the container by starting unwanted Transactions.
 
So next time when you are using these methods make sure to mark the transaction type as NOT_SUPPORTED an opposed to NEVER because NOT_SUPPORTED only blocks the current transaction until the end of the method where as NEVER throws a remote exception.


No comments:

Post a Comment