0

I am working on an enterprise application (EJB 2.1). In this app, whenever a user login, it is creating remote interface of a Stateless Session Bean and storing it in Session as an attribute.

This is the pseudo code:

HttpSession httpSession = null; // user's session
MyEjb myEjb = null; // Remote interface of EJB


// get session of the user
httpSession = ...;

// create remote interface of EJB
myEjb = ...;

// store remote interface of EJB in Session as an attribute
httpSession.setAttribute("MyEjb", myEjb);

Then for each EJB call it first gets the remote interface from the Session and then use it.

HttpSession httpSession = null; // user's session
MyEjb myEjb = null; // Remote interface of EJB


// get session of the user
httpSession = ...;

// get remote interface of EJB from session 
myEjb = (MyEjb) httpSession.getAttribute("MyEjb");

// use the EJB

What are the pros of cons of using this approach? Does it make sense? Thanks

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
srh
  • 1,661
  • 4
  • 30
  • 57
  • Why are you doing this? – kolossus Mar 06 '16 at 20:14
  • I am not doing this. This is an existing application and the programmers who code this way are not with this company anymore. I am trying to figure out the reasons of why they do it this way. – srh Mar 07 '16 at 00:26
  • 1
    I can't see any reason why this would be necessary (or even useful): SLSBs are pooled at startup (so no performance gains to be had by clinging to a specific instance) and handed out by the container on request by a client - hanging on to a specific instance at best means that you're bloating the size of your sessions; at worst, you're causing the container to instantiate more beans to satisfy other clients/sessions. – kolossus Mar 07 '16 at 03:08

0 Answers0