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

How Stateless Bean work.  RSS feed

 
Bennet Xavier
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

i have a bean as shown below, i didnt include the Remote interface,




if i call the method with interface's object in the servlet the value of x is getting incremented,

stateless bean means it should not maintain the states. but its incrementing by one every time.

please clear my doubt, if i am wrong.

Thanks In Advance,

Bennet Xavier. X
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

stateless bean means it should not maintain the states. but its incrementing by one every time.

The value will be incremented if your client call is hitting the same instance of the EJB which it may be doing. All object instances have some sort of state until they are garbage collected. You cannot however rely on this state in a stateless bean because the next call from a client might be directed by the container to a different EJB instance, which is why your variable x is dangerous.
 
Bennet Xavier
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul Sturrock,

You mean to say, don't use instance variable.

Thank You for your reply.
 
Marty Fried
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bennet Xavier wrote:Hi Paul Sturrock,

You mean to say, don't use instance variable.

Thank You for your reply.

It is good programming practice to always initialize variables to some known value, if possible, although Java seems to remove much of that necessity. But you may not agree with Java's initialization value, so it's good to think about it out of habit, I think.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!