Look at the below code
EJB Object
EJB Home
Session Bean
import javax.ejb.*;
public class FortuneBean implements SessionBean
{
private String[] yourFortune = {"Fortune and glory, kid. Fortune and glory",
"You're gonna get killed chasing after your damn fortune and glory!",
"Feels like I stepped on a fortune cookie!",
"The fortune cookie will slip right through your fingers!",
"It's not a cookie, it's a bug!",
"It is your time to do research and dig up the treasure!",
"It is your year!",
"While looking for a fortune cookie, hold on to your potatoes!",
"You are in a position unsuitable to give orders!"};
String name = "No Name? " ;
public void ejbActivate()
{
System.out.println("From ejbActivate()");
}
public void ejbPassivate()
{
System.out.println("From ejbPassivate()");
}
public void ejbRemove()
{
System.out.println("From ejbRemove()");
}
SessionContext sc;
static int count;
public void setSessionContext(SessionContext ctx)
{
sc = ctx;
count++;
System.out.println("From setSessionContext()");
try
{
FortuneHome home = (FortuneHome)sc.getEJBHome();
Fortune fortuner = home.createMessagesWithName("Athulya " + count);
//Fortune fortuner = home.create();
System.out.println(fortuner.getNextFortune());
System.out.println(fortuner.getMyMessage());
}
catch (Exception e)
{
e.printStackTrace();
}
}
public String getNextFortune()
{
System.out.println("From getNextFortune(): ");
int randomNum = (int) (Math.random() * yourFortune.length);
return name + " -> " + yourFortune[randomNum];
}
public String getMyMessage()
{
System.out.println("From getMyMessage(): ");
return name + " -> " + " None but the brave deserves the fair.";
}
public void ejbCreate()
{
System.out.println("From ejbCreate()");
}
public void ejbCreateMessagesWithName(String name)
{
System.out.println("From ejbCreateMessagesWithName()");
this.name = name;
}
}
Inside the setSessionContext() method, i am creating another bean. So the creation of beans must go on infinitly. right?
But when i run the client code, it starting with continous creation of beans. But its stops automatically within some seconds.
Please anyone tell me why it is stoping the execution?