Bill
Bill

Reputation: 33

Using CommonJ WorkManagerTaskExecutor Spring 3 for multithreading

Hello everyone I am new to the forum and I just had a question about working with Spring's commonj WorkManagerTaskExecutor. I have been on a bunch of forums looking for better information on the subject but I haven't seen anything detailed on the subject. So here is my situation.

My application uses multiple threads which were being handled by ThreadPoolTaskExecutor which a friend told me he thought would not be the correct choice since we are using websphere 7.0 application server. I had everything working correctly and with some minor tweaking was able to replace the ThreadPoolTaskExecutor with a WorkManagerTaskExecutor. When I run the application the threads fire off via the default work manager on the websphere server. The problem that seems to be happening though is that even though I am using the workManagerTaskExecutor.waitForAll(collection,timeout); It never actually waits for the threads to complete. I know that it is working that is the threads are executing their respective methods because if you issue a lengthy for loop after all of this the data is there where as if you do not the data is not there. I was wondering the following two things.

  1. Is the WorkManagerTaskExecutor the way to go? Or would using a ThreadPoolTaskExecutor be sufficient for handling multiple threads on a enterprise web application?

  2. If the WorkManagerTaskExecutor is the way to go? Any ideas as to why the waitForAll method is completing as if the methods are done? When clearly they are not? After the page loads I can see in the logging that the methods are still running and eventually completeing.

Any help would be much appreciated. If I left anything out I will gladly try and give more information about the issue as I truly appreciate any help that might be given.

Thanks in Advance,

Bill

Upvotes: 3

Views: 5421

Answers (2)

Bill
Bill

Reputation: 33

The final winning combination to this problem for me ended up being:

List<Callable<?>> callables = new ArrayList<Callable<?>>();
    List<Future<?>> futures = new ArrayList<Future<?>>();
    for (int i = 0; i<callers.length;i++){
        callables.add(new MainTaskExecutor(this,entity,callers[i]));

    }
    for (Callable c:callables){
        futures.add(workTaskExecutor.submit(c));
    }
    for (Future<?> f:futures){
        do{}while(!f.isDone());
    }

Upvotes: 0

Drew
Drew

Reputation: 1937

You should implement your concurrent class by extending the java.util.concurrent.Executor interface built into JavaSE, and then using the Spring IoC container, you can inject in an implementation class of WorkManagerTaskExecutor when running under Websphere.

This will give you flexibility if you ever want to run on another Java app server, and even works if you run outside a container directly on the JVM, since you could inject in a ThreadPoolTaskExecutor and not have to change any code.

You should avoid coding against the CommonJ WorkManager API (JSR 237) directly, such as using the waitForAll method, since it only works on IBM Websphere and Oracle WebLogic.

Upvotes: 3

Related Questions