• 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

singleton stateless session bean

 
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello

how to do it?

thanks in advance!!
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can't be done. What are you trying to achieve?
 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i only want all the client code always get the same session bean instance!!!
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stateless session bean instances are pooled by the container. When client invokes a method on a stateless session bean, container moves the bean instance back to the pool once the method completes. There is no way you can make a single stateless session bean instance to receive all the client calls. The next time client invokes another method on the same stateless session bean, container chooses any bean instance from the pool and the client has no control over it.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by zb cong:
i only want all the client code always get the same session bean instance!!!



I think what you are looking for is more along the lines of a Stateful Session Bean?
 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but i think the stateful session bean is session special, but i want a GLOBAL singletion
[ June 08, 2006: Message edited by: zb cong ]
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then EJB is the wrong technology to use. Why must every client connect to just one instance of a class?
[ June 08, 2006: Message edited by: Paul Sturrock ]
 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it just my thinking, there is not real work request, considering:

if i want to instantiate many java objects when the session bean is created,then every session bean will keep the same copies of these objects,it is resource consuming, so i think if i can make this session bean singleton, it maybe sovle this problem. what do you think?
 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think out a solution, don't know if it works as what i want.

write a singleton java class, in this singleton class, i find the session bean by jndi then create the instance, and save the reference within the singleton, every client code can get referece to the session bean, can it promise the session bean singleton?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Turn that around. Allow any number of session bean instances but do the work in a POJO that gets a singleton in the normal fashion.

If your goal is to cache something less than one instance of common data per session bean this will do the job. If your goal is to cache exactly one (two would be failure) I'd worry about the container using different classloaders causing you to make multiples.
reply
    Bookmark Topic Watch Topic
  • New Topic