Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Mona Mehta   on Jun 29 In Java Category.

  
Question Answered By: Coleman Smith   on Jun 29

According the EJB spec states, you can not use synchronized keyword or static fields in EJBs but you can call to the classes that does use them, you never know what is the difference while container is the one managing this for you, so the solution would be simple but tricky.

As Amin is saying, you might end up saving data to be contained out of your EJBs and keep them in data source. this means that a session bean can implement SessionSynchronization interface to perform run a check before and after any transaction to this data source; assuming you have already set the proper transaction attribute to perform a lock/unlock on the resource (which could be a table of your classes according to your example). Your session bean can be the one performing the query to the table and returning a result which indicate availability of free space in the class.

Aside from that, an interesting discussion that I've seen somewhere else is the use of GoF singleton within EJBs i.e. something like the way a local service locator is implemented with in a cluster. sounds a bit strange for the EJB to call out to a singleton but doable. but one note that you can not used it for read and write as it may block threads created by container on EJBs.
If you want to use the singleton approach, read chapter 11 of Mastering EJB 3rd Ed, (Writing Singletons in EJB). That would be very helpful specially if you have more than one cluster.

Share: