Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Singleton and EJB  RSS feed

 
Mrutyunjay Hanchinal
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
I have a requirement of having a single EJB object in the EJB tier, this is basically to reduce the time taken to create EJB object as my EJB stores some static valeues.
So I want something like this
From Client side I will look up EJB, say EJB with JNDI name 'A' Then I will get an EJB object say 'objA'
Some other client will lookup the EJB A
Then I should get objA only.
How do I achieve this?
Thanks in anticipation
Mrutyunjay
 
William Dimac
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could create the ejb as a wrapper to the singleton object. I.e. let the server create as many ejb objects as it wants. Each of them would then have a pointer to the singleton object. Note this prevents you from distributing this component across multiple JVM's.
The preferred choice is to just create a stateless bean and allow the server to create as many beans as it needs. They only get instantiated once and the server can keep them in a pool to be used as needed. This allows the server to scale your application more readily.
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I discuss the stateless session bean wrapper to a singleton (with example code) in this article.
Kyle
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!