Search code examples
javaconcurrencyweblogicjndischeduledexecutorservice

How to create a custom ManagedScheduledExecutorService in weblogic.xml and use it in java code?


How can I lookup my custom ManagedScheduledExecutorService that I am defining in the weblogic.xml of my application?

I have tried to use the InitialContext.lookup but it does not work. It throws the NamingException.

My weblogic.xml looks something like this;

    <wl-dispatch-policy>CustomWorkManager</wl-dispatch-policy>
    <work-manager>
        <name>CustomWorkManager</name>
        <min-threads-constraint>
            <name>CustomWorkManager-MinThreads</name>
            <count>1</count>
        </min-threads-constraint>
        <max-threads-constraint>
            <name>CustomWorkManager-MaxThreads</name>
            <count>20</count>
        </max-threads-constraint>
    </work-manager>
    <managed-scheduled-executor-service>
        <name>CustomMSES</name>
        <dispatch-policy>CustomWorkManager</dispatch-policy>
    </managed-scheduled-executor-service>

I am trying to lookup my CustomMSES managed scheduled executor service as follows;

    InitialContext ic = new InitialContext();
    execService =
            (ManagedScheduledExecutorService) ic.lookup("CustomMSES");

Am I missing something?

I am new to the JNDI lookup concept, so I may be doing something wrong. I do see in blogs that they have added something like "java:comp/env" before the name. But I could not find a logic for this kind of naming.

I am sure if the JNDI lookup string is rectified I should be able to run my code correctly.

Can anyone help suggest what could be missing?


Solution

  • Changing my lookup value from

    "CustomMSES"
    

    to

    "java:comp/env/concurrent/CustomMSES"
    

    seems to have done the trick!