Re: Clarification regarding ManagedExecutorService in Rx Client
Andy McCright
Hi Markus,
Thanks for the response. I understand that open sourcing of Java EE to Eclipse has put things in a sort of "limbo", so I'll just try to focus on the technical aspects of this thread.
This example might help illustrate the problem better - suppose that we have a Java EE application that uses a servlet and two EJBs:
in Servlet:
@Resource
ExecutorService nonManagedExecutor;
// initial Rx request
CompletionStage stage = clientBuilder.executorService(managedExecService).build().target(uri).request().rx().method(...);
// first "stage" task
stage.thenRunAsync( new Runnable() {
public void run() {
Context ctx = new InitialContext();
SomeObject x = ctx.lookup("java:comp/env/somethingSpecificToThisModule");
...
}, nonManagedExecutor);
}
ejb1.syncMethod(stage);
ejb2.asyncMethod(stage);
in EJB 1:
@Resource
ManagedExecutorService managedExecutorService;
@RunAs("Admin")
public void syncMethod(CompletionStage stage) {
stage.thenRunAsync( new Runnable() {
public void run() {
Context ctx = new InitialContext();
SomeOtherObject x = ctx.lookup("java:comp/env/somethingSpecificToThisEJB");
// do some work that only the Admin role can perform
...
}
}, managedExecutorService);
}
in EJB 2:
@Resource
ManagedExecutorService managedExecutorService;
@Asynchronous
public Future<Something> asyncMethod(CompletionStage stage) {
stage.thenRunAsync( new Runnable() {
public void run() {
Context ctx = new InitialContext();
SomeThirdObject x = ctx.lookup("java:comp/env/somethingSpecificToThisOtherEJB");
...
}
}, managedExecutorService); }
So, in this example, we've got a servlet that has one set of contexts (security, transaction, java:* naming, metadata, etc.), and two EJBs with separate contexts - one runs as the Admin role, one is asynchronous, so it runs on a separate thread. Each of these components adds a new stage with a specified ManagedExecutorService. Which contexts should these runnables execute with?
In EJB 1, the only way the app will function is if security context from EJB 1 is used in that method's Runnable, but is that the intent of the spec? Or should EJB 1's Runnable use the Servlet's context since that is where the CompletionStage was first created? Or should it use the context of the previous stage (i.e. the Runnable from inside the Servlet's method - which doesn't transfer context since it is a non-managed executor service)?
I think the most intuitive answer is that the context should be transferred from the thread calling the "thenRunAsync" method. Otherwise in the example above, the Runnables in the EJBs have no idea what context they are executing with - i.e. a different servlet might have different contexts when invoking the EJBs.
Does that make sense? Does anybody have other suggestions for what the proper behavior of the CompletionStage should be?
Thanks again,
Andy
J. Andrew McCright IBM WebSphere Development +1 507 253 7448 TL 553-7448 andymc@...
----- Original message -----
|
|