Hi Srinivasan, There is actually something else which you should be doing in your code. Stateless session beans are kept in pools, correct? When the container places the bean instance in the pool, the values of your instance variables go with it, UNLESS, you initialize your instance variables to their default values at the end of the business methods or something similar. DO NOT initialize them in the constructor and expect good results (you can guess why).

Hi Srinivasan, Stateless session bean doesn't hold the conversational states between client calls but it doenst guarantee to re-initialize the bean every time a client calls.

In your case, if you have more than one client programs calling the same bean, it still gives the increasing order numbers for different clients.

For example: you have 2 cleints and you made a call on client-1: get the value 0 and cleint-2 calls on the same bean and he will get the value as 1 (Since bean was not re initialized) and again client-1 calls: he will get the value as 2 ...so this is the case with Stateless session beans.

Your Stateless session bean hold states (if you define instance variable in your bean class) but these states are not the conversational states with the CURRENT client. The current client may hold a reference and can make multiple calls on the reference. But each call time, it may use a different bean in the bean pool, so it may not get what you want. You can make mutilple test clients (threads)to see the problem.

The stateless means the bean does not maintain the conversational states.

Srinivasan Rengan
Ranch Hand

Joined: Nov 07, 2004
Posts: 122

posted May 10, 2006 12:51:00

0

Thanks everyone, for your interesting apt replies.

I have actually tried to call the bean from different clients, i.e tried to execute the program from different windows. But, the sequence of numbers seems to be growing. 1) Now, If at all I have to re-intialize the values, where should I do that. From the console, I find that, the ejbCreate() method is invoked only once, inspite of me calling the business method many times.

2) Now, if this is the behaviour potrayed by the stateless bean, then how does the state maintanance play a part in a stateful session bean. Because, I can use the instance variable in by stateless bean to preserve the state.

Thanks

wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023

posted May 10, 2006 13:30:00

0

1) Now, If at all I have to re-intialize the values, where should I do that. From the console, I find that, the ejbCreate() method is invoked only once, inspite of me calling the business method many times.

For stateless session bean, you may have to re-intialize the values in each method. Any one has good idea?

2) Now, if this is the behaviour potrayed by the stateless bean, then how does the state maintanance play a part in a stateful session bean. Because, I can use the instance variable in by stateless bean to preserve the state.

The states (values) are not conversational states, the instance variables are shared by different clients. Stateful session bean keeps the conversational states for ONE client as long as it alive. Think about using a Stateful bean as a shop cart for a customer.

If you ever have state(instance variables) in stateless session bean that is going to be mess. Though there is no strict rule, but you should not be depending on instance variables in SLSB. Declare all variables which you need to manipulate inside method and use them.