• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static final object defined in stateless bean

 
sanjay r tiwari
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if we define static final bean class instance in
a stateless session bean than wether we are going
to have its one copy or not to all the client
 
Rahul Mahindrakar
Ranch Hand
Posts: 1868
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sanjay could you please rephrase your question I am not able to understand what you are asking.
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you asking whether all clients would (effectively) have access to the same static variable?
Well, because of issues around class loaders, server clustering and so on, you might in fact have more than one copy of the static variable alive at any one point in time. This is why it is not advisable to use statics for read-write variables.
Therefore, all clients might not have access to the same version.
Hope that answers your question.
Simon
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i assume that i w'd be deploying my application in only one applcn server, do you think i still can't depend on the static variable?
Do you expect more than 1 copy of the bean class file in the memory since we have multiple class loaders?
Actually I have a session bean which delegates some of the operations to another java class.
I'm holding on to the instance of the class inside
my session bean as a static final variable.
What is your opinion about this?
which takes me to my next question.
Is'nt there anway i can delegate tasks from a stateless session bean? I did'nt want my utility classes to be EJB/ APP server specific.
i mean, i want it to be a simple java class which can be called from anywhere.
OR
i was just wodnering, there's not much of initialization that i do inside my utility classes. if that's the case i really don't mind
certain things getting intialized twice.
thanks.
Originally posted by Simon Brown:
Are you asking whether all clients would (effectively) have access to the same static variable?
Well, because of issues around class loaders, server clustering and so on, you might in fact have more than one copy of the static variable alive at any one point in time. This is why it is not advisable to use statics for read-write variables.
Therefore, all clients might not have access to the same version.
Hope that answers your question.
Simon
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic