Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Stateless session bean...

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok... I have a statless session bean as follows... I've removed the exception decs for clarity...
public class MattBean implements SessionBean {
public void ejbCreate(){ System.out.println( "CREATED MATT BEAN" ) ; }
public void ejbRemove(){ System.out.println( "REMOVING MATT BEAN" ) ;}
public void ejbActivate() { System.out.println( "MATT EJBACTIVATE" ) ; }
public void ejbPassivate() { System.out.println( "MATT EJBPASSIVATE" ) ; }
public String getMattyBoy() { return "***MATTYBOY IS COOL***" ;}
}
And a test program which creates the bean and calls the method getMattyBoy() 5 times in a simple for loop.
I would expect to see
CREATED MATT BEAN
***MATTYBOY IS COOL***
***MATTYBOY IS COOL***
***MATTYBOY IS COOL***
***MATTYBOY IS COOL***
***MATTYBOY IS COOL***
And may be the removed message at some point in the future...
However, I get
CREATED MATT BEAN
***MATTYBOY IS COOL***
REMOVING MATT BEAN
CREATED MATT BEAN
***MATTYBOY IS COOL***
REMOVING MATT BEAN
CREATED MATT BEAN
***MATTYBOY IS COOL***
REMOVING MATT BEAN
CREATED MATT BEAN
***MATTYBOY IS COOL***
REMOVING MATT BEAN
CREATED MATT BEAN
***MATTYBOY IS COOL***
REMOVING MATT BEAN
Now that can't be right can it ??? I would next exxpect the instance to be removed after every call. I have a socket connect in my ejbCreate and it's killing me !
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope. In some circumstances I might pretty much expect what you're seeing. Download the EJB 1.1 spec. Take a look at figure 16 on page 73. Then take a look at figure 17 on page 74. What is happening is that the EJB container is keeping the size of the method-ready pool at one. Now as to why it's that low -- you've got me...
From what you've described (a socket connect in an ejbCreate?) it sounds like you're really describing a STATEFUL session bean instead of a stateless one... What are you doing with that socket connect? You're either setting some data (not bloody likely since there's nothing you could set) or getting some data to put in a variable (which means you really want a STATEFUL bean instead).
Kyle
 
Matt Sumner
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From O'Reilly EJB book..
"stateless session beans are not subject to activation, so they can maintain open connections to resources for their entire lifecycle. If for eg an open network socket was needed, it could be opened in the ejbCreate() method when the stateless seesion is initially created. This resrc can theb be maintained in a normal instance var and kept open...... The ejbRemove() method should close any open rsrcs..."
There follows a caveat that some vendors may remove the bean after each invocation...
This is exactly what I'm doing. Now, JRun does what I expect but websphere does not.
Who knows how to increase the instance pool size in websphere.
 
He's dead Jim. Grab his tricorder. I'll get his wallet and this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic