Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EJBs and syncronized methods...  RSS feed

 
Max Tomlinson
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!