Proactive insights, news and tips from Oracle WebLogic Server Support. Learn Oracle from Oracle.

  • November 25, 2015

Concurrency Utilities support in WebLogic Server 12.2.1, Part Four: ContextService


ContextService is for creating contextual proxy objects. It provides
method createContextualProxy to create a proxy object, then proxy object
methods will run within the captured context at a later time. 

Server provides a preconfigured, default ContextService for each
application, and applications can easily use it in web or EJB components
without any configuration. Let's begin with a simple example that
uses default ContextService.

Example-1: Execute a task with the creator's context using a ExecutorService

Step1: Write the task. In this simple example, the task extends Runnable.

public class SomeTask implements Runnable {

    public void run() {

        // do some work



Step2: SomeServlet.java injects the default ContextService, uses the ContextService to create a new contextual object proxy for SomeTask, then submit the contextual object proxy to a Java SE ExecutorService. Each invocation of run() method will have the context of the servlet that created the contextual object proxy.


public class SomeServlet extends HttpServlet {

    @Resource ContextService cs;

    @Resource ManagedThreadFactory mtf;

    ExecutorService exSvc = Executors.newThreadPool(10, mtf);

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        SomeTask taskInstance = new SomeTask();

        Runnable rProxy = cs.createContextualProxy(taskInstance, Runnable.class);

        Future f =  = exSvc.submit(rProxy);

        // Process the result and reply to the user 



Runtime Behavior

Application Scoped Instance

ContextServices are
application scoped. Each application has its own default
ContextService instance, and the lifecycle of the
ContextService instances are bound to the application. Proxy objects
created by ContextServices are also application scoped, so that when the
application is shut down, invocations to proxied interface methods will
fail with an IllegalStateException, and calls to
createContextualProxy() will  throw an IllegalArgumentException

Server only provides a default ContextService instance for each
application, and does not provide any way to configure a ContextService.

Context Propagation

ContextService will
capture the application context at contextual proxy object creation,
then propagate the captured application context before invocation of
contextual proxy object methods, so that proxy object methods can also
run with the application context.

Four types of application
context are propagated: JNDI, ClassLoader, Security and WorkArea. The
propagated context types are the same for four types of the concurrent
managed objects.

Related Articles:

See for more details Configuring Concurrent Managed Objects in the product documentation.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha