• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EJBs and syncronized methods...

 
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic