• 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

Doubt of instances pool

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the bean instances of a stateless bean or message driven bean are the same to all clients, why needs a pool of bean instances(not only one instance) ?
thanks to your help !
 
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lee,
Welcome to JavaRanch !

If the bean instances of a stateless bean or message driven bean are the same to all clients, why needs a pool of bean instances(not only one instance) ?


For a given bean class, to let the container serve multiple clients concurrently.
Best,
Phil.
[ December 15, 2003: Message edited by: Philippe Maquet ]
 
Lee Ming
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Philippe,
thanks for your reply, but my doubt is that I think the container uses multiple threads to serve multiple clients concurrently, is that right?
If it is right, so why the threads serve the clients do not use one same instance? I knows that if a bean instance is not thread save, then the container should use multiple bean instances to serve clients, is a bean instance of statless bean or message driven bean thread save ?
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I think the container uses multiple threads to serve multiple clients concurrently, is that right?


Yes

If it is right, so why the threads serve the clients do not use one same instance?


Because all the calls made by container on stateless and message driven beans are serialized i.e. no 2 threads will be executing same method of one particular bean instance and thus to support concurrency container manitains pool of bean instances.

Is a bean instance of statless bean or message driven bean thread save ?


No, as explained above.
Hope this helps. Please refer to spec for more details.
Ashish
[ December 15, 2003: Message edited by: Ashish Pagare ]
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To answer the question, a bean instance is MAY NOT be the same for all clients of a stateless session bean. You never know whether you are calling method on the same bean instance you were talking to. The container might have got a new instance from the pool to serve your next request.
Consider this scenario:
1. Container has 3 bean instances in a pool, A, B and C.
2. Client 1 makes a method invocation, which is served by A.
3. Client 2 makes a method invocation, which is served by B.
4. Meanwhile container might moved A back to pool.
5. Next time client 1 makes a method invocation, container may choose C to serve this request.
Having a pool of bean instances can facilitate multiple clients calling methods on EJB at the same time. Cocunrrency is different issue.
Hope it helps.
Regards,
Nandu
 
Lee Ming
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to all of you!
Now I know the fact is that the container must ensure that only one thread can be executing an instance at any time(spec 7.11.8 & 15.8.3).
But I have another question, why does the EJB spec give such restriction to message driven bean and stateless session bean? I ask this question since I think the instances(from the same home if it have) of a bean class(message driven or stateless session) are equivalent to all clients! Is that means the states of such instaces are not the same to the container durning a business method invocation?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic