This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring Boot in Practice and have Somnath Musib on-line!
See this thread for details.
Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Is this execution stops unexpectedly?

 
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
reply
    Bookmark Topic Watch Topic
  • New Topic