Stateless Bean - scope of instance variable in EJB Timer call back function

Hi,
I would like to know on the scope of an instance variable of a Stateless Bean object,
when used in a EJB Timer call back.Let me explain this in more detail below.
I have a requirement to use a EJB Timer.
For this, I have created a stateless object since Timer creation needs to be done
from a stateless bean. I have a member variable "count" of the stateless bean class.
In the timer call back(ejbTimeout), I am able to use this count variable during
each time of the call back, and the value of this variable is also updated properly.
I have a few queries with respect to the above behaviour:
1) Does stateless bean object not get destroyed once the Timer is created from the Bean?
2) If the Bean object is not destroyed, then when does the bean object get destroyed?
3) If both (1) and (2) are not true, then can anyone explain on how the above behaviour is possible?
Thanks in advance,
Ulrich

Hi Ulrich,
The ejb timer is associated with the stateless session bean component, not with a particular bean instance. There is no formal relationship between the bean instance that called createTimer() and the bean instance on which the timer callback happens. If they're the same in your test run that's just a coincidence and not something your application should be depending on.
In the stateless session bean model, the container can create and destroy stateless session bean instances at any time. The container is free to pick any stateless session bean instance to service any client invocation or timer callback. If you need to pass context into a timer callback, one way to do it is via the timer "info" object. However, the info object is immutable so it wouldn't be a good match for a counter. You could of course always just use a database for any necessary coordinated state.
--ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Doubt about scope of instance variable

    Hi All,
    i have a doubt about scope of instance variable.
    if i declare a instance variable in servlet , i want to know whether it can be shared(means everywhere ) or not.
    thanks in advance
    Gopal

    The servlet container will create one servlet object, and run multiple threads through its service() / doGet() / doPost() methods.
    That means that any instance variables of the servlet are shared between multiple requests, and can cause problems with threads accessing the same variable..
    To make your servlets thread-safe
    1 - have no instance variables - only use local variables in the doGet/doPost method.
    2 - use the session scope for storing variables you need over multiple calls.
    Cheers,
    evnafets

  • Scope of instance variables in servlets..

    Hi all,
              Sorry for asking a dumb question..
              What is the scope of instance variables in a servlet? Is the scope is
              limited to thread?
              In other words, in the following example, i am setting "testStr", in one
              request and when i tried to access the same instance variable from another
              request, i am getting it as null. Does it mean instance variable is limited
              to that particular thread/request?
              thanks in advance..
              -ramu
              

    Oops ... I had misunderstood and had the problem backwards ;-)
              > Is it known behavior? With registered servlet its working fine (a
              > instance variable is shared by all requests)
              I believe so; I typically deploy in a WAR so have not seen the problem that
              you describe. Servlets can be reloaded, so what you saw could have been
              caused bye a date/time mismatch between the .class file and the server's
              current time. On the other hand, that could be how WebLogic works.
              Peace,
              Cameron Purdy
              Tangosol, Inc.
              http://www.tangosol.com
              +1.617.623.5782
              WebLogic Consulting Available
              "Ramu" <[email protected]> wrote in message
              news:[email protected]...
              > Hi Purdy,
              >
              > I got it. I am testing the servlet as a unregistered servlet, which is
              > creating instance for every new request!!!, which created this whole
              > confusion. Is it known behavior? With registered servlet its working fine
              (a
              > instance variable is shared by all requests)
              >
              > > What theory? ;-) Instance variables are on the object, and the object
              can
              > > be used by multiple threads, thus allowing multiple threads to access
              the
              > > same instance variables.
              > what i mean by theory here is, all instance variables in servlet should
              be
              > shared by all requests. Now i got it sir.
              >
              > Thank you..
              > -ramu
              >
              >
              > >
              > > Peace,
              > >
              > > --
              > > Cameron Purdy
              > > Tangosol, Inc.
              > > http://www.tangosol.com
              > > +1.617.623.5782
              > > WebLogic Consulting Available
              > >
              > >
              > > "Ramu" <[email protected]> wrote in message
              > > news:[email protected]...
              > > > Hi,
              > > >
              > > > > No, an instance variable in a servlet class is not limited to a
              > thread.
              > > > There
              > > > > is exactly one copy of the servlet created in memory and all
              requests
              > > pass
              > > > > through the same instance, thus sharing any instance variables. A
              > > couple
              > > > of
              > > > > things to remember:
              > > > I totally agree with you, But i am wondering why my sample servlet(i
              am
              > > > attaching the file) is not sharing the instance variables across
              > > > threads/reqs. (in 1st request set some string to "testStr" instance
              > > > variable, in next request if you read the same instance variable, you
              > will
              > > > get null!!)
              > > > Our current code is having instance variables. But right now we are
              not
              > > > getting any problems. But as per theory, instance variables should be
              > > shared
              > > > across threads/requests..
              > > >
              > > > Any how we are changing our code to remove all instance variables.
              > > >
              > > > thanks,
              > > > -ramu
              > > >
              > > > >
              > > > > 1.) Using instance or class variables in servlets that are not
              > read-only
              > > > is not
              > > > > a good thing to do. This makes the servlet not thread-safe. To
              > > maintain
              > > > > variables across requests, sessions, etc., use the servlet-defined
              > > objects
              > > > to
              > > > > store the state (e.g., request, session, etc.).
              > > > >
              > > > > 2.) If you modify the servlet class on disk, WebLogic will reload
              the
              > > > servlet
              > > > > class thus discarding the old instance and creating a new one (of
              > > course,
              > > > this
              > > > > depends on some configuration parameters for servlet reloading).
              > > > >
              > > > > Hope this helps,
              > > > > Robert
              > > > >
              > > > > Ramu wrote:
              > > > >
              > > > > > Hi,
              > > > > > thanks for quick reply.
              > > > > > I am not at all using SingleThreadModel. See the following code.
              > > > > > In first request i am passing "abc" value to testStr. But in
              second
              > > > request,
              > > > > > I am getting null for testStr in second request. It looks like
              (for
              > > me)
              > > > for
              > > > > > non single threaded model also, scope of instance variables is
              > > limited
              > > > to
              > > > > > Thread/Request.. But as per theory, because its not single
              threaded
              > > > model,
              > > > > > only one instance should be there AND testStr(instace variables)
              > > should
              > > > be
              > > > > > shared across the all threads. But i am not able see that
              behaviour
              > > > here.
              > > > > > But if declare instance variable as static, o am able to share
              it
              > > > across
              > > > > > all threads/requests.
              > > > > >
              > > > > > note:
              > > > > > From browser i am setting testStr to "abc" with URL like
              > > > > > "localhost/test1?testStr=abc"
              > > > > > And 2nd req from browser is like "localhost/test1" (on server
              > output
              > > i
              > > > am
              > > > > > getting null for testStr)
              > > > > >
              > > > > > Any ideas?
              > > > > >
              > > > > > thanks,
              > > > > > -ravi
              > > > > >
              > > > > > import java.io.*;
              > > > > > import javax.servlet.*;
              > > > > > import javax.servlet.http.*;
              > > > > >
              > > > > > public class test1 extends HttpServlet
              > > > > > {
              > > > > > public String testStr;
              > > > > >
              > > > > > public void doGet (HttpServletRequest req, HttpServletResponse
              res)
              > > > > > throws ServletException, IOException
              > > > > > {
              > > > > > doPost(req, res);
              > > > > > }
              > > > > >
              > > > > > public void doPost (HttpServletRequest req,
              HttpServletResponse
              > > res)
              > > > > > throws ServletException, IOException
              > > > > > {
              > > > > > try {
              > > > > > res.setContentType("text/html");
              > > > > > PrintWriter out = res.getWriter();
              > > > > > if(req.getParameter("testStr") != null)
              > > > > > {
              > > > > > testStr = req.getParameter("testStr");
              > > > > > System.out.println("set testStr = " + testStr);
              > > > > > }
              > > > > > else{
              > > > > > System.out.println("get testStr = " + testStr);
              > > > > > }
              > > > > >
              > > > > > }
              > > > > > catch(Exception e){
              > > > > > e.printStackTrace();
              > > > > > }
              > > > > >
              > > > > > }
              > > > > > }
              > > > > >
              > > > > > "Cameron Purdy" <[email protected]> wrote in message
              > > > > > news:[email protected]...
              > > > > > > Yes or no, depending on if your servlet implements
              > > SingleThreadModel.
              > > > > > >
              > > > > > > See the servlet 2.2 spec for documentation on how many instances
              > of
              > > a
              > > > > > > servlet will be created. See the doc for the SingleThreadModel
              > > > interface.
              > > > > > >
              > > > > > > Peace,
              > > > > > >
              > > > > > > --
              > > > > > > Cameron Purdy
              > > > > > > Tangosol, Inc.
              > > > > > > http://www.tangosol.com
              > > > > > > +1.617.623.5782
              > > > > > > WebLogic Consulting Available
              > > > > > >
              > > > > > >
              > > > > > > "Ramu" <[email protected]> wrote in message
              > > > > > > news:[email protected]...
              > > > > > > > Hi all,
              > > > > > > >
              > > > > > > > Sorry for asking a dumb question..
              > > > > > > >
              > > > > > > > What is the scope of instance variables in a servlet? Is the
              > scope
              > > > is
              > > > > > > > limited to thread?
              > > > > > > >
              > > > > > > > In other words, in the following example, i am setting
              > "testStr",
              > > in
              > > > one
              > > > > > > > request and when i tried to access the same instance variable
              > from
              > > > > > another
              > > > > > > > request, i am getting it as null. Does it mean instance
              variable
              > > is
              > > > > > > limited
              > > > > > > > to that particular thread/request?
              > > > > > > >
              > > > > > > > thanks in advance..
              > > > > > > >
              > > > > > > > -ramu
              > > > > > > >
              > > > > > > >
              > > > > > > >
              > > > > > >
              > > > > > >
              > > > >
              > > >
              > > >
              > > >
              > >
              > >
              >
              >
              

  • Scope of instance variables clarification requested

    under the topic "Scope of instance variables" in the class notes for the course i'm doing it is stated:
    inside the class definition, the name can be prefixed by the keyword "this".
    e.g. available = this.balance + overdraft;
    in simple words, please explain what it means
    or:
    what is a class definition? and what does using "this" mean?
    i'll gladly take internet links on where i can find the answer to my own question if you don't have time.
    thanks a million!

    this can be regarded simply as a reference variable which points to the intance of the class it's used in.
    So this.fieldOne referer to the instance field fieldOne withing the current instance just as theOther.fieldOne refers to the instance field in another object.

  • Small question on ejb's call back methods?

    Hi I just don't want to use the declarative security where we configure roles, users and methods in deployment descriptors. I have written authorization code in a method and this method should be called before any business method is called to check authorization. Is this possible? if so how?
    Edited by: murrayb9654 on Aug 27, 2010 12:00 PM

    you'll want to look into interceptors. You can configure an interceptor to invoke on EVERY EJB call.
    Check out this blog for example:
    [http://www.adam-bien.com/roller/abien/entry/interceptors_ejb_3_for_absolute|http://www.adam-bien.com/roller/abien/entry/interceptors_ejb_3_for_absolute]
    For the ejb-name, you can put * to indicate it should be invoked for all EJB calls, or you can put a more specific pattern.

  • Viewing Instance Variable Information for Automatic activities

    Hi,
    I have a process which is made up of all automatic activities that each do a specific set of activities and populate a few instance variables. I want to create a view so that a user can see the state and value contained in each of the instance variable at any time during the execution of the process. A example of what i want to achive in the view is shown below.. any advice on how to design such a feature
    InstVar_1 InstVar_2 InstVar_3
    1 2 3
    4 5 6
    Thanks.

    Are you the one who commented out the code you're looking for ?//String desc = StringFactory.getString(attributes.getValue("desc"));You just have to modify you AttributeObject class to hold a new field : String description. And then, it's up to you to create a new constructor or a new setter method.
    Btw, this is not a Swing related question.

  • Inheritance - instance variable initialization

    Hi all.
    I have a question regarding inherited instance variables.
    class Animal {
       int weight;
       int age = 10;
    class Dog extends Animal {
       String name;
    class Test {
       public static void main(String[] args) {
          new Dog();
    }This is just an arbitrary code example.
    When new Dog() is invoked, I understand that it's instance variable "name" is give the default
    type value of null before Dog's default constructor's call to super() is invoked.But Im a little perplexed about
    Animals instance variables. I assume that like Dog, Animals instance variables are given their default type values
    of 0 & 0 respectively, before Animals invocation of super(); What im unclear about is that at the point that weight and age are given their default type values, are Dog's inherited weight and age variables set to 0 aswell at that exact moment? Or are Dog's inherited weight and age variables only assigned their values after Animals constructor fully completes because initialization values are only assigned to a classes instance variables after it's call to super().
    Many thanks & best regards.

    Boeing-737 wrote:
    calvino_ind wrote:
    Boeing-737 wrote:
    newark wrote:
    why not throw in some print statements and find out?Super() or this() have to be the very first statement in a constructor..
    Also you cannot access any instance variables until after super or this.
    :-S
    Kind regardsbut if you add the "print" statement in animal constructor, you can easily see what happened to the attributes of Dog ; that s the trick to print "before" super()You can never add a print before super(). It's a rule of thumb, super() and this() must always be the first statements
    in a constructor, whether added implicitly by the compiler or not. In this case there are 2 default constructors (inserted by the compiler), each with a super() invocation. Even if i added them myself and tried to print before super(), the compiler would complain.
    Thanks for the help & regards.you didn't understand what i meant ; take a look at that:
    class Animal {
       int weight;
       int age = 10;
       public Animal() {
           Dog thisAsADog = (Dog) this;
          System.out.println(thisAsADog.name);
          System.out.println(thisAsADog.x);
    class Dog extends Animal {
       String name;
       int x = 10;
    public class Test {
       public static void main(String[] args) {
          new Dog();
    }this way you will know what really does happen

  • EJB 3.0 Stateful bean not saving state while Stateless bean is !!!

    My Stateless bean is as follow:
    package test;
    import javax.ejb.Stateless;
    @Stateless(mappedName = "StatelessBean")
    public class StatelessBean implements StatelessBeanRemote {
         int counter;
         public void increment(){
              System.out.println("Stateless counter value:"+counter);
              counter++;
    My Stateful bean is as follow:
    package test;
    import javax.ejb.Stateful;
    @Stateful(mappedName = "StateFulBean")
    public class StateFulBean implements StateFulBeanRemote {
         int counter;
         public void increment(){
              System.out.println("Stateful counter value:"+counter);
    Client is as follows:
    package test;
    import java.util.Hashtable;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    public class TestClient {
         public static void main(String[] args) {
              Hashtable hashtable = new Hashtable();
              hashtable.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
              hashtable.put(Context.PROVIDER_URL, "t3://localhost:7001");
              InitialContext ic;
              try {
                   ic = new InitialContext(hashtable);
                   StateFulBeanRemote stateFulBeanRemote = (StateFulBeanRemote)ic.lookup("StateFulBean#test.StateFulBeanRemote");
                   stateFulBeanRemote.increment();
                   StatelessBeanRemote statelessBeanRemote = (StatelessBeanRemote)ic.lookup("StatelessBean#test.StatelessBeanRemote");
                   statelessBeanRemote.increment();
              } catch (Exception e) {
                   e.printStackTrace();
    The output i am getting after running the client twice is as follows:
    //first time
    Stateful counter value:0
    Stateless counter value:0
    //second time
    Stateful counter value:0
    Stateless counter value:1
    Shouldn't the counter values be incremented in case of Stateful bean and remain the same for Stateless bean. But the output that I am getting is the complete opposite !!!
    Can anyone please explain this confusing behavior of stateless and stateful ejb 3.0 beans.

    868664 wrote:
    Can anyone please explain this confusing behavior of stateless and stateful ejb 3.0 beans.It is very simple: a stateless bean is ASSUMED to be stateless; you cannot keep state in a stateless bean as a contractual rule. That doesn't mean that you will fail to keep state in them at least for a little while, they are still only Java objects. Generally stateless EJBs are pooled, so you may get the same instance each time you use such an EJB, but you may just get another one. It is not dependable and the rules say don't do it - so don't do it.
    A stateful bean is tied to a single client, and so can be used by a client to keep state in it. Since You are running the client application twice you are operating with two different clients and so you will get a new stateful bean each time and your code will keep printing 0. However there is also a bug in your code:
    public void increment(){
    System.out.println("Stateful counter value:"+counter);
    }You are not incrementing anything.

  • Stateful session bean destroying instance variables?

    I'm trying to use a stateful session bean as some kind of login controller and to maintain the login id and access level across JSPs and HTMLs so that once logged in, all the JSPs can obtain the login name of the current user (String) and his access level (int).
    I use the login.jsp to login and it successfully reports logging in with the correct access level retrieved from database. However, if I go to another JSP (testlogin.jsp), these 2 EJB instance variables are always destroyed and set to null and 0 when I access them again.
    What am I missing that my stateful session bean is not saving these instance variables? Do I need to put them in some serializable value objects (create a help VO class?)
    I suspected that on different JSP, I call the MemberControllerHome.create() method, it creates a new instance or something but if I don't use the create method how do I get a handle to MemberController at all?
    MemberControllerBean.java
    public class MemberControllerBean implements SessionBean {
         //initialize in ejbCreate.
         private MemberHome memberHome;
         SessionContext context;
         //Member currentLogin;
         //Current Login
         private String loginID;
         private int accessLevel;
         // Constructor
         public MemberControllerBean() {}
    ...some code in between...
    public void login(String id, String password){
              try{
                   Member member = null;
                   member = memberHome.findByPrimaryKey(id);
                   if(member.getMPassword().equals(password)){
                        this.loginID = member.getMID();
                        this.accessLevel = member.getMAccessLevel();
                   else{
                        throw new EJBException("Login failed. Invalid member ID and/or password.");
              } catch (FinderException ex) {
                   throw new EJBException("Login failed. Invalid member ID and/or password.");
         public void logout(){
              this.loginID = null;
              this.accessLevel = 4;
         public String getLoginID(){
              return this.loginID;
         public int getLoginAccessLevel(){
              return this.accessLevel;
    login.jsp
    String mID = request.getParameter("mID");
    String mPassword = request.getParameter("mPassword");
    out.println("20:" + mID + ":" + mPassword);
    if(mID != null && mPassword != null){
         out.println("22:" + mID + ":" + mPassword);
         try{
              InitialContext ic = new InitialContext();
              MemberControllerHome home = (MemberControllerHome) ic.lookup("java:comp/env/ejb/MemberController");
              MemberController mc = home.create();
              out.println("26:Logging in as " + mID + " with " + mPassword);
              mc.login(mID, mPassword);
              out.println("28:" + mc.getLoginID() + "logged in successfully at level " +
                   mc.getLoginAccessLevel() + ".");
         } catch (NamingException ex) {
              out.println("java:comp/env/ejb/MemberController not found.");
         } catch (EJBException ex) {
              out.println(ex.getMessage());
         } catch (Exception ex) {
              out.println(ex.getMessage());
    testlogin.jsp
    <%
    try{
         InitialContext ic = new InitialContext();
         MemberControllerHome home = (MemberControllerHome) ic.lookup("java:comp/env/ejb/MemberController");
         MemberController mc = home.create();
         out.println("You are logged in as <b>" + mc.getLoginID() +
              "</b> at level <b>" + mc.getLoginAccessLevel() + "</b>.");
    } catch (NamingException ex) {
         out.println("java:comp/env/ejb/MemberController not found.");
    } catch (EJBException ex) {
         out.println(ex.getMessage());
    } catch (Exception ex) {
         out.println(ex.getMessage());
    %>

    The key to the problem is that in testlogin.jsp a new stateful session bean is created. The new bean instance of course doesn't know the log-in information you stored in the old session bean. That is why the method returns null and 0 when called.
    There are couple of ways to solve the issue. The easiest solution is to store the bean instance created in Login.jsp in the jsp's implicit HttpSession object. Because login.jsp and testlogin.jsp share the same session, the bean instance can be easily stored and retrieved.
    Here is the code you need to have:
    1. in login.jsp
    session.setAttribute("MemberControllerBeanInstance", mc);
    2. in testlogin.jsp
    MemberController mc =
    (MemberController) session.getAttribute("MemberControllerBeanInstance");
    Hope it helps.

  • Exception while getting the server instance. Stateless bean problem

    Hi,
    New to OC4J, I'm moving an ear that was running ok under jboss.
    1- The wep app deploys. This is a piece of code inside the init() method of a struts plugin:
         System.out.println("0");
         AddressFacadeHome addressFacadeHome = HomeFactory.getAddressFacadeHome();
         System.out.println("1.0");
         AddressFacade addressFacade = addressFacadeHome.create();
         System.out.println("1.5");
    2- The code is run when the web app is initialized. This is the error message I get. system.out show that the error occurs on addressFacadeHome.create().
    AddressFacade is a remote/local stateless bean. HomeFactory returns the jndi lookup/narrow of the remote object.
    0
    1.0
    caught exception while getting the server instance null
    java.lang.NullPointerException
    com.evermind.security.User com.evermind.server.ThreadState.getCurrentUser()
    ThreadState.java:637
    com.evermind.security.User com.evermind.server.ThreadState.getUser()
    ThreadState.java:371
    fda.common.address.ejb.interfaces.AddressFacade AddressFacadeHome_StatelessSessionHomeWrapper7.create(
    AddressFacadeHome_StatelessSessionHomeWrapper7.java:66
    void fda.web.oaa.struts.plugin.ApplicationInit.init(org.apache.struts.action.ActionServlet, org.apache
    .struts.config.ModuleConfig)
    void org.apache.struts.action.ActionServlet.initModulePlugIns(org.apache.struts.config.ModuleConfig)
    ActionServlet.java:1105
    void org.apache.struts.action.ActionServlet.init()
    ActionServlet.java:468
    void javax.servlet.GenericServlet.init(javax.servlet.ServletConfig)
    GenericServlet.java:258
    com.evermind.server.http.ServletInstanceInfo com.evermind.server.http.HttpApplication.loadServlet(com.
    evermind.util.ByteString)
    HttpApplication.java:1956
    com.evermind.server.http.ServletInstanceInfo com.evermind.server.http.HttpApplication.findServlet(com.
    evermind.util.ByteString)
    HttpApplication.java:4355
    void com.evermind.server.http.HttpApplication.initPreloadServlets()
    HttpApplication.java:4455
    void com.evermind.server.http.HttpApplication.initDynamic(com.evermind.server.http.HttpApplicationConf
    ig)
    HttpApplication.java:662
    void com.evermind.server.http.HttpApplication.<init>(com.evermind.server.Application, com.evermind.ser
    ver.http.HttpSite, com.evermind.server.http.HttpApplicationConfig, java.lang.String, java.lang.String, boolean
    My guess is that it's a jaas issue (because i see security and getCurrentUser), but at init time, no user is authenticated.
    Any clue would be very much appreciated. Let me know if I can provide anything else, such as deployment descriptors.
    Thanks,
    Christophe.

    After spending some time on this, I looked at the source code for com.evermind.server.ThreadState
    This is the code that throws the exception:
    if(applicationThread != null && applicationThread.httpHandler != null && applicationThread.servletInfo != null)
    try
    server = applicationThread.httpHandler.request.getApplication().getApplication().getServer();
    catch(Throwable t)
    System.out.println("caught exception while getting the server instance " + t.getMessage());
    t.printStackTrace(System.out);
    It looks like this method expects a httpRequest, and would find null because I'm in the servlet.init()
    (at least, that's my interpretation)
    I tested my code (the remoteFacade.create()) inside of a jsp, and it worked...
    So, the next logical question is:
    Can I make EJB calls from within the init method of a servlet? (or more specifically from a struts plugin, which I believe should be more or less the same thing)
    If so, do I need to take extra steps?
    Again, any experience/help on this will be much appreciated.
    Thanks,
    Christophe.

  • Instance of ejb2 stateless bean

    InitialContext ctx = new InitialContext();
    Object objref = ctx.lookup(PARAMCTRL_IJNDIName.SBAppComboDb);
    homeAppComboDb = (SBAppComboDbHome) PortableRemoteObject.narrow(objref, SBAppComboDbHome.class);
    remoteAppComboDb = homeAppComboDb.create();
    1)How many instance of that particular stateless bean is created in ejb container?
    2)Does instance of stateless being destroy after ejbRemove()? which mean can be garbage colletion.
    3)can other user sharing use the same instance of the stateless bean after remove?
    4)is stateless bean thread safe?

    Please read tutorial for EJB 2.0 Stateless Session Bean

  • Keeping alive an instance of a Stateless Bean

    Hello Weblogic comunity:
    I'm deploying a stateless bean with initial-beans-in-free-pool element in '1' (Weblogic 7.0). According with the EJB spec, at some moment of EJB lifecicle ejbRemove() will be called by the container removing the instance :(
    Is there a way to keep 1+ instances always alive?

    Hans,
    "Hans Nemarich" <[email protected]> wrote in message news:19065530.1096384306132.JavaMail.root@jserv5...
    Hello Weblogic comunity:
    I'm deploying a stateless bean with initial-beans-in-free-pool element in '1' (Weblogic 7.0). According with the EJB spec, at somemoment of EJB lifecicle ejbRemove() will be called by the container removing the instance :(
    >
    Is there a way to keep 1+ instances always alive?Please check this:
    http://www.viewtier.com/newsgroups/thread.jspa?threadID=23&tstart=0
    Regards,
    Slava Imeshev

  • Restrict number of stateless bean instances

    i need to restrict number of stateless bean instances. Am working on EJB3.0 and jboss.
    I have even modified the following in standardjboss.xml but, still am not able to restrict.......
    <container-pool-conf>
    <MaximumSize>10</MaximumSize>
    <strictMaximumSize>true</strictMaximumSize>
    </container-pool-conf>
    Is there any other way?
    Thank in advance

    all the config files are different in jboss for the ejb3 stuff (rather annoying). assuming you want to make this change globally, you need to alter the deploy/ejb3-interceptors-aop.xml file. at the end of the "Stateless Bean" domain there is an annotation element which defines the pool configuration (it's basically a copy of the java annotation embedded in the xml file).

  • Servlet Instance Variable scope

    Just want to clarify my understanding of instance variables in regards to Servlets.
    public class TestServlet extends HttpServlet
        public String instVariable = "";
    public void processRequest(HttpServletRequest request, HttpServletResponse response)
          instVariable = request.getParameter("param");
          response.sendRedirect( instVariable ) ;
    }If two users both enter the processRequest logic at the same time, is it possible that they will both get the same
    result? My understanding of this was that if they each execute the first line, then each execute the second
    line, each user would be redirected to the same instVariable that was set by the second request.
    What would be the easiest way to stop this from happening? syncronized? ThreadSafe?
    I just want a simple clarification.
    Thanks for the insight.

    If two users both enter the processRequest logic at
    the same time, is it possible that they will both get
    the same
    result? My understanding of this was that if they
    each execute the first line, then each execute the
    second
    line, each user would be redirected to the same
    instVariable that was set by the second request. Yes, it is possible, since there is only one instVariable.
    What would be the easiest way to stop this from
    happening? syncronized? ThreadSafe? The easiest way to avoid that is to simply not use an instance variable. Use a local variable, declared within your processRequest method. Each thread (i.e. each user of the servlet) has its own set of local variables.

  • How can I use evaluate to get the instance variable in customized tag

    1.
    At first , I create a class called bean,and declared several params in it and do not define any getter function for the param.
    class bean{
    String param = "test";
    SomeClass scObj = new SomeClass();
    2.
    The second ,I use
    request.setAttribute("beanObj",new bean());
    3.
    And then I wanna use the customized tag to show a text box , then initialize it's value.
    <salt:text name="param" value="beanObj.param">
    <salt:text name="obj" value="beanObj.scObj.func()">
    4.
    I tried the evaluator provided by JexlContext ,Struts, JSTL and it seems that if I do not define the getter for the variable ,I can not get the bean's instance variable's value.
    Expression e = ExpressionFactory.createExpression( value );
    JexlContext jc = JexlHelper.createContext();
    jc.getVars().put(strInitBeanName, request.getAttribute("beanObj"));
    Object obj = e.evaluate(jc);
    the result of the obj is null....
    Can anybody recommand some other evaluator can get the value of a instance variable from an object?

    do you have any other suggestion ? Nops, somebody else may have though. AFAIK, all lookups of the type
    beanName.propertyNameuse reflection on the getXXX() methods to access the property.
    Having said that, I guess you could write one though in a custom tag, using the same - reflection (you will ahve to rely on the java.lang.reflect.Field class quite heavily) - but that would be reinventing the wheel for most other functionality that you would have to include (like looking up the bean in scope etc)
    cheers,
    ram.

Maybe you are looking for