Hi All,
I have written a stateless
EJB using EJBGEN to generate the Home, remote & deployment descriptors. I am using weblogic 7.0.2 with jdk 1.3.1_02
The problem is that when I run my client.java to access the "Demo Stateless EJB" and call demoSelect() which returns i+1 on each call, I would expect that it would always be "1". This is because the Bean is stateless and does not have any information stored between to invocation.
But on each call I get the next number.
What's even more strange is when the client is run from different JVM's, I still get the next number in the sequence ...???
I am going mad.... Could someone please tell be why or point me in the right direction.
Thanks
I have included the code for anyone who may be interested.
import java.io.*;
import java.util.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import ejb.demo.*;
public class Client
{
public static void main(
String[] args) throws Exception
{
System.out.println("Creating InitialContext : " + new Date());
Context ic = new InitialContext();
System.out.println("Lookup : " + new Date());
DemoSSHome ssHome1 = (DemoSSHome) ic.lookup("sgs.DemoSSTest");
System.out.println("Create Home : " + new Date());
DemoSS ss1 = ssHome1.create();
System.out.println("Execute method : " + new Date());
System.out.println(ss1.demoSelect());
System.out.print("Hit <Ret> to continue...");System.in.read();
System.out.println("Lookup : " + new Date());
DemoSSHome ssHome2 = (DemoSSHome) ic.lookup("sgs.DemoSSTest");
System.out.println("Create Home : " + new Date());
DemoSS ss2 = ssHome2.create();
System.out.println("Execute method : " + new Date());
System.out.println(ss2.demoSelect());
System.out.println("Execute method : " + new Date());
System.out.println(ss2.demoSelect());
System.out.print("Hit <Ret> to continue...");System.in.read();
System.out.println("Lookup : " + new Date());
DemoSFHome sfHome1 = (DemoSFHome) ic.lookup("sgs.DemoSFTest");
System.out.println("Create Home : " + new Date());
DemoSF sf1 = sfHome1.create();
System.out.println("Execute method : " + new Date());
System.out.println(sf1.demoSelect());
System.out.println("Execute method : " + new Date());
System.out.println(sf1.demoSelect());
System.out.println("Execute method : " + new Date());
System.out.println(sf1.demoSelect());
System.out.print("Hit <Ret> to continue...");System.in.read();
System.out.println("Lookup : " + new Date());
DemoSFHome sfHome2 = (DemoSFHome) ic.lookup("sgs.DemoSFTest");
System.out.println("Create Home : " + new Date());
DemoSF sf2 = sfHome2.create();
System.out.println("Execute method : " + new Date());
System.out.println(sf2.demoSelect());
System.out.print("Hit <Ret> to continue...");System.in.read();
}
}
/**
* DemoBean -- This is implemented by the EnterPrise Bean author
*
* This class must extend javax.ejb.SessionBean and implement
* the methods in this interface as well as providing the
* implementation of the business methods.
*
* Note: this is the first time you have had to write any code
* so far everything else has had its implementation
* generated for you.
*/
package ejb.demo;
import javax.ejb.*;
import java.io.Serializable;
import java.util.*;
import java.rmi.*;
import javax.naming.*;
/**
* @ejbgen:session
* ejb-name = DemoSSBean
* type = Stateless
* max-beans-in-free-pool = 100
*
* @ejbgen:jndi-name
* remote = sgs.DemoSSTest
*
* @ejbgen:ejb-client-jar
* file-name = demo_client.jar
*/
public class DemoSSEJB implements SessionBean {
static final boolean verbose = true;
private SessionContext ctx;
private transient Properties props;
private int count = 0;
// Implement the methods in the SessionBean interface
public void ejbActivate() {
if (verbose)
System.out.println("Stateless ejbActivate called");
}
public void ejbRemove() {
if (verbose)
System.out.println("Stateless ejbRemove called");
}
public void ejbPassivate() {
if (verbose)
System.out.println("Stateless ejbPassivate called");
}
/**
* Sets the session context.
*
* @param SessionContext
*/
public void setSessionContext(SessionContext ctx) {
if (verbose)
System.out.println("setSessionContext called");
//this.ctx = ctx;
//InitialContext context = new InitialContext();
//props = (Properties) context.lookup("java:comp/env");
}
/**
* This method corresponds to the create method in the home interface
* "interfaces.DemoHome.java".
* The parameter sets of the two methods are identical. When the client calls
* <code>DemoHome.create()</code>, the container allocates an instance of
* the EJBean and calls <code>ejbCreate()</code>.r
*/
public void ejbCreate () {
if (verbose)
System.out.println("Stateless ejbCreate called");
}
/**
*
* ******* HERE IS THE BUSINESS LOGIC *************
* Do the demoSelect() here ==> don't even go to the database in this eg.
*
* @ejbgen:remote-method
*/
public String demoSelect()
throws RemoteException
{
count++;
return("SS : " + count);
}
/**
* Returns the
JDBC pool name.
*
* @return string JDBC pool name
*/
// public String getDatabaseName() {
// return (String)props.get("jdbcPoolName");
//}
}