Request context for session without beans state

Is there a request-bound context for an EJB3 session - beans? My environment is Java-EE-5.

In this example

@Remote(SessionFacade.class) @Stateless
public class SessionFacadeBean implements SessionFacade {
  @EJB
  private Other bean;

  public void myBusinessMethod() {
     // TODO: get or create *myRequestScope*
     *myRequestScope*.put("demo", Integer.valueOf( 1 ));
     bean.otherBusinessMethod();
     sysout(*myRequestScope*.get("demo"));
  }
}

@Local(Other.class) @Stateless
public class OtherBean implements Other {
  public void otherBusinessMethod() {
     // TODO: get or create *myRequestScope*
     *myRequestScope*.put("demo", Integer.valueOf( 2 ));
  }
}

should always print "2" when calling SessionFacadeBean # myBusinessMethod () - regardless of concurrent calls.

I have no luxury using CDI. And it should also work regardless of transactional propagation (therefore, JCA is also not an option).

+3
source share
2 answers

EJB, , , . , , , bean .

, ThreadLocal, , , . , , . ,

  • Thread EJB-; . , ThreadLocal , , . , , ThreadLocal .
  • , ThreadLocal, , .
+1

- beans?

: .

: -. . Requestscope - -.

  • - , , Hashmap. , Hashmap .

  • singleton ( , , ehcache).

  • EJB 3.1 @Singleton

  • stateful Beans Beans, , .

0

All Articles