Have the
ExecutorService
configured first in weblogic.xml.1 2 3 4 5 6 7 8 9 | <!-- weblogic.xml --> < managed-executor-service > < name >CustomMES</ name > < max-concurrent-long-running-requests >10</ max-concurrent-long-running-requests > </ managed-executor-service > < resource-env-description > < resource-env-ref-name >concurrent/CustomMES</ resource-env-ref-name > < resource-link >CustomMES</ resource-link > </ resource-env-description > |
Then name it in web.xml.
1 2 3 4 5 | <!-- web.xml --> < resource-env-ref > < resource-env-ref-name >concurrent/CustomMES</ resource-env-ref-name > < resource-env-ref-type >javax.enterprise.concurrent.ManagedExecutorService</ resource-env-ref-type > </ resource-env-ref > |
Now, you can ask for it.
1 2 3 4 5 6 7 8 9 10 11 12 13 | public static ExecutorService getExecutorService() { try { // Get our own, defined in weblogic.xml return InitialContext.doLookup( "java:comp/env/concurrent/CustomMES" ); } catch ( final NamingException e) {} try { // Fallback level 1: Get the Java EE 7 default MES return InitialContext.doLookup( "java:comp/DefaultManagedExecutorService" ); } catch ( final NamingException e) {} // Fallback level 2: Return the default pool. // This always exists. In fact, every Java8 threaded feature uses this. return ForkJoinPool.commonPool(); } |
@Resource
annotation with the mappedBy
attribute, if you have properly configured beans.The
ExecutorService
is already an Executor
, so you can pass it to eg. a CompletableFuture
:1 2 3 4 5 6 | CompletableFuture< void > future = CompletableFuture .supplyAsync(Frobolator::aSupplier, getExecutorService()) .thenAccept(result -> bar(result)); // Later, wait for the Future, if necessary. future.join(); |
But properly using
CompletableFuture
s are another topic...Implementation of the
ManagedExecutorService
in WebLogic is here: $ORACLE_HOME\wlserver\modules\com.oracle.weblogic.concurrent.jar