File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and Other Java EE Technologies and the fly likes EJBs and syncronized methods... Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » EJB and Other Java EE Technologies
Reply Bookmark "EJBs and syncronized methods..." Watch "EJBs and syncronized methods..." New topic
Author

EJBs and syncronized methods...

Max Tomlinson
Ranch Hand

Joined: Jul 17, 2001
Posts: 364
Hi all-
I have a question reagrding EJBs and syncronization of resources: I'm getting conflicting info, basically that I can and cannot use 'syncronized'.
What I need to do (this is somewhat similar to the lock table in the SCJD exam) is to use a singleton to issue pre-instantiated MQ connections to callers. The callers would use a stateless session bean to get the reference to the MQ Session Manager singleton which would manage connections through a hashtable (the lock table).
I know hashtable is syncronized but I believe there is still a window between the get (checking for whether a connection has been issued) and a put (marking the connection as in-use).
In the non-EJB model, I could simply syncronize the method which does the get and put.
Can I do this in the singleton that is called by a stateless session bean? I've seen an example of a statefull bean that does something similar (basically syncronizing he singleton instance, locking in that manner).
thanks in advance,
Max Tomlinson

Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3878
OK,
In fact, the EJB Spec prevents you from making an EJB method synchronized. However, it does NOT prevent you from making methods that are parts of utility classes CALLED by an EJB from being synchronized. So move your hashtable into a utility class, put the synchronized keyword on the method you need and call away from your EJB.
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Kyle,
I understand the EJB spec also prohibits creating new threads. Is this, like synchronization, also allowed in a separate utility class?
Thanks in advance,
-Miftah
 
 
subject: EJBs and syncronized methods...
 
Threads others viewed
JDBC pool monitor, bean monitor and others
Websphere MQ and MDB and Administered objects
Data source connection usage during nested method calls
Stateless Session Bean Problems Singleton
WebSphere transaction timeout
IntelliJ Java IDE

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture