views:

2548

answers:

4

Hi there!

I have to execute long running threads in a WebLogic Bea 10.0 M1 server environment. I tried to use WorkManagers for this. Using an own WorkManager allows me to specify my own thread timeout (MaxThreadStuckTime) instead of adjusting the timeout for the whole business application.

My setup is as follows:

weblogic-ejb-jar.xml:

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-ejb-jar xmlns="http://www.bea.com/ns/weblogic/90" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-ejb-jar.xsd"&gt;

    <weblogic-enterprise-bean>
        <ejb-name>TestBean</ejb-name>
        <resource-description>
            <res-ref-name>myWorkManager</res-ref-name>
            <jndi-name>wm/myWorkManager</jndi-name>
        </resource-description>
    </weblogic-enterprise-bean>

</weblogic-ejb-jar>

weblogic-application.xml:

<?xml version="1.0" encoding="UTF-8"?>
<weblogic xmlns="http://www.bea.com/ns/weblogic/90" xmlns:j2ee="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.bea.com/ns/weblogic/90
    http://www.bea.com/ns/weblogic/90/weblogic.xsd"&gt;

    <work-manager>
        <name>myWorkManager</name>
        <ignore-stuck-threads>1</ignore-stuck-threads>
    </work-manager>

</weblogic>

and the Bean:

import javax.annotation.Resource;
import javax.ejb.Stateful;

import weblogic.work.WorkManager;

@Stateful(mappedName = "TestBean")
public class TestBean implements TestBeanRemote {

    @Resource(name = "myWorkManager")
    private WorkManager myWorkManager;

    public void test() {
        myWorkManager.schedule(new Runnable() {

            public void run() {
                while (true) {
                    System.out.println("test: +++++++++++++++++++++++++");
                    try {
                        Thread.sleep(45000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

            }
        });
    }
}

When I try to deploy this things, the server gives me the following exceptions:

[EJB:011026]The EJB container failed while creating the java:/comp/env namespace for this EJB deployment.
weblogic.deployment.EnvironmentException: [EJB:010176]The resource-env-ref 'myWorkManager' declared in the ejb-jar.xml descriptor has no JNDI name mapped to it. The resource-ref must be mapped to a JNDI name using the resource-description element of the weblogic-ejb-jar.xml descriptor.

I try to figure out how to access / use WorkMangers for days now, and still get this or that as an exception. Very frustrating!

Thanks in advance!

+1  A: 

BEA (together with IBM) have developed a framework specifically for managing long-running tasks in a JEE environment. Take a look at CommonJ.

The Spring Framework offers some convenience classes around this framework.

R. Kettelerij
A: 

You need to name your work manager. The way we do it is in our Ear project EarContent/META-INF/weblogic-application.xml

<wls:work-manager>
   <wls:name>wmBatch</wls:name>
   <wls:ignore-stuck-threads>true</wls:ignore-stuck-threads>
</wls:work-manager>

(which you appear to have done)

and then we use the annotations to set the manager:

@MessageDriven(ejbName =..., dispatchPolicy = "wmBatch")

And then there is no coding around getting the work manager. This might work for you.

John Liptak
+1  A: 

You need to remove the WorkManager refrence from your weblogic-ejb-jar.xml, this refenece should go to ejb-jar.xml.

Infact I doubt if Weblogic schema definition "weblogic-ejb-jar.xsd" will allow you to add a reference element, you must be getting xsd validation errors.

anyways, get rid of the element

resource-description from weblogic-ejb-jar.xml

<weblogic-enterprise-bean> 
    <ejb-name>TestBean</ejb-name> 
    <resource-description> 
        <res-ref-name>myWorkManager</res-ref-name> 
        <jndi-name>wm/myWorkManager</jndi-name> 
    </resource-description> 
</weblogic-enterprise-bean> 

it will look like this

weblogic-ejb-jar.xml

<weblogic-enterprise-bean>
    <ejb-name>TestBean</ejb-name>
</weblogic-enterprise-bean>

your workManager reference will go to ejb-jar.xml like this.

ejb-jar.xml

 <enterprise-beans>
    <session>
        <ejb-name>TestBean</ejb-name>
        <ejb-class>com.xxx.TestBean</ejb-class> <!-- your package com.xxx-->
        <resource-ref>
            <res-ref-name>myWorkManager</res-ref-name>
            <res-type>commonj.work.WorkManager</res-type>
            <res-auth>Container</res-auth>
        </resource-ref>
    </session>
</enterprise-beans>

Now to get WorkManager from JNDI I'm doing

InitialContext ctx = new InitialContext();
this.workManager = (WorkManager) ctx.lookup("java:comp/env/myWorkManager");

but I belive annotation will work equally well.

@Resource(name = "myWorkManager")

my weblogic-application.xml looks same as shared above

<weblogic> 
<work-manager> 
    <name>myWorkManager</name> 
    <ignore-stuck-threads>1</ignore-stuck-threads> 
</work-manager> 

This is working for me .. let me know if needed I can share my full code.

you can view your WorkManager and load on it by going to Weblogic Admin Console Home—>Deployments—>yourApp—>Monitoring(Tab)—>WorkLoad(Tab)”

Ujj
A: 

it's not working for me im using Jersey 1.1.4.1 and WebLogic 10.3 on CentOS 5.4 I need to make everything in WAR (only webapp). It's not showing in monitoring tab...

Anish Sneh