-
1. Re: Automatic Destroy State in Stateful Session Bean
grdzeli_kaci Oct 4, 2006 1:03 PM (in response to grdzeli_kaci)I think i had ideological mistake :(
-
2. Re: Automatic Destroy State in Stateful Session Bean
grdzeli_kaci Oct 4, 2006 2:09 PM (in response to grdzeli_kaci)ok, I find another problem :
1.i have interfacepackage com.magti.businesslayer.ejb3entity.oracle; import javax.ejb.Remote; @Remote public interface MyState { public void initialize(); }
2. Implementation :package com.magti.businesslayer.ejb3entity.oracle; import javax.ejb.Remote; import javax.ejb.Stateless; @Stateless @Remote(MyState.class) public class StateBean implements MyState { String name = null; public void initialize() { if (name == null) { System.out.println("Null"); name = "Initialize"; } else { System.out.println("Not Null -> "+name); } } }
3. Test Client
package com.magti.businesslayer.ejb3entity.oracle;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
public class TestMain
{
public static void main(String[] args)
{
try
{
Properties jndiProps = new Properties();
jndiProps.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
jndiProps.setProperty(Context.URL_PKG_PREFIXES,
"org.jboss.naming:org.jnp.interface");
jndiProps.setProperty(Context.PROVIDER_URL,
"jnp://192.168.9.136:1099");
InitialContext ctx = new InitialContext(jndiProps);
MyState state = (MyState) ctx.lookup("StateBean/remote");
state.initialize();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}when i run client fierst time i get this result :
21:47:33,652 INFO [STDOUT] Nullsecond time :
21:47:34,652 INFO [STDOUT] Nullthird time :
21:47:35,652 INFO [STDOUT] Initializeforth time
21:47:36,652 INFO [STDOUT] Initializefifth time :
21:47:37,652 INFO [STDOUT] Initialize..... ..... can anybody explain me why ? this session bean is stateless.
-
3. Re: Automatic Destroy State in Stateful Session Bean
alrubinger Oct 4, 2006 2:40 PM (in response to grdzeli_kaci)You have an instance variable in your bean. By "Stateless", this means the container will not guarantee that the same instance will be returned to the same client on each invocation. At the end of the invocation, it's just returned to the pool. It's up to the developer to ensure the bean has no instance variables within that instance, or that all are reset to a common state, such that all instances in the pool can be considered "equal" and handed out to any client without evidence of that instance's history.
S,
ALR -
4. Re: Automatic Destroy State in Stateful Session Bean
grdzeli_kaci Oct 6, 2006 1:30 AM (in response to grdzeli_kaci)ok, thanks ALRubinger
i think than i need always returned new instance for the same client.
i think that stateless session bean always must return new instance to the client when i lookup from from the client...
i did some changes on my sample bean :public void initialize() { System.out.println(this); if (name == null) { System.out.println("Null"); name = "Initialize"; } else { System.out.println("Not Null -> "+name); } }
and it fiert time prints09:10:21,759 INFO [STDOUT] com.magti.businesslayer.ejb3entity.oracle.StateBean@dd8904 09:10:21,759 INFO [STDOUT] Null
and then always printed :09:10:21,759 INFO [STDOUT] com.magti.businesslayer.ejb3entity.oracle.StateBean@dd8904 09:10:21,759 INFO [STDOUT] Not Null -> Initialize