Posted on

Using WorkManagers in your applications

If you do not explicitly assign a Work Manager to an application, it will use the default Weblogic Work Manager. A module can be assigned to your custom Work Manager by using the <dispatch-policy> element in the deployment descriptor. As an alternative, you can define new Work Managers in your deployment descriptors through the <work-manager> element and associate as well constraints to them. Let’s see how to apply both approaches for all supported descriptors (weblogic.xml, weblogic-ejb-jar.xml, weblogic-application.xml):

Applying a Work Manager in your Web applications (weblogic.xml)

If you want to apply your Work Manager policies in your Web applications, you can reference it through the wl-dispatch-policy element in the weblogic.xml file. In the following example, we are using the ExampleWM (that we have formerly created through the Web console):

<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">     <wl-dispatch-policy>ExampleWM</wl-dispatch-policy>  </weblogic-web-app>

Web applications can even reference a Work Manager at more granular level, such as at Servlet level, by setting the parameter wl-dispatch-policy as init parameter of your servlet. In the following example, we are associating the ExampleWM Work Manager with Servlet “WorkServlet”:

<web-app>   <servlet>     <servlet-name>WorkServlet</servlet-name>     <servlet-class>workservlet.WorkServlet</servlet-class>     <init-param>                           <param-name>wl-dispatch-policy</param-name>       <param-value>ExampleWM</param-value>     </init-param>   </servlet>  </web-app>

Applying a Work Manager in your EJBs (weblogic-ejb-jar.xml)

Work Manager can be as well bound to a specific EJB application by mentioning it into the dispatch-policy element of the weblogic-ejb.jar.xml. In the following example, we are binding the ExampleWM to our WorkEJB:

<weblogic-ejb-jar>     <weblogic-enterprise-bean>        <ejb-name>WorkEJB</ejb-name>        <jndi-name>core_work_ejb_workbean_WorkEJB</jndi-name>        <dispatch-policy>ExampleWM</dispatch-policy>     </weblogic-enterprise-bean>  </weblogic-ejb-jar>

Applying a Work Manager in your application (weblogic-application.xml)

If you want to define a Work Manager and use it across all modules contained in EAR, then you can define it into the WLS Enterprise application descriptor named weblogic-application.xml file. In the following example, we are defining a Work Manager named JEEScopedWorkManager with Min and Max constraints:

<weblogic-application>    <max-threads-constraint>      <name>j2ee_maxthreads</name>      <count>50</count>   </max-threads-constraint>    <min-threads-constraint>      <name>j2ee_minthreads</name>      <count>1</count>   </min-threads-constraint>    <work-manager>      <name>JEEScopedWorkManager</name>   </work-manager> </weblogic-application>