Discussions

EJB programming & troubleshooting: can we define private variables inside a stateless session bean

  1. can we define private variables inside a stateless session bean
  2. Of course, just dont expect them to be the same value between method calls. (As in you might be talking to a different bean).

    So if bean has following.

    private String hellotext;

    public void setHellotext(String s){
    this.hellotext = s;
    }
    public String getHellotext(){
    return this.hellotext;
    }

    ---
    No problem having bean hold on to private variables as long as you know that you can not achieve the functionality of a stateful bean


    and your EJBObject stub that client sees exposes these methods, if your client does.

    stub.setHellotext("ssss");
    System.out.println(stub.getHellotext());

    It is not gaurranteed to print out sss because of stateless session bean pooling.
  3. if i define some private varibles in the stateless session bean, will it affect the performance in any way.
  4. No it won't affect the performance .