How to use WorkManager with GlassFish 3?
I need to launch a background task from a servlet in a GlassFish server, and I figured WorkManager开发者_StackOverflow社区 was a somehow Java EE-compliant way to achieve this.
Previously in Glassfish v2 it worked reasonably well: I used the static method WorkManagerFactory.createWorkManager(String poolName) which gave me a WorkManager that I could use to start a Work with startWork(Work).
In GlassFish v3.0.1 the API changed: there is no more static createWorkManager() method in WorkManagerFatory, and the createWorkManager takes 2 extra parameters: a resource adapter name, and a ClassLoader. I'm confused: how am I supposed to get a WorkManager now??
I tried to instantiate the WorkManagerFactory myself and call createWorkManager() but I get the following exception:
An error occurred during instantiation of the work manager for resource-adapter [ jmsra ] java.lang.NullPointerException at com.sun.enterprise.connectors.work.WorkManagerFactory.getConnectorRuntime(WorkManagerFactory.java:202) at com.sun.enterprise.connectors.work.WorkManagerFactory.createWorkManager(WorkManagerFactory.java:122)
The available documentation on this subject is very scarce to say the least... so any help will be greatly appreciated.
For what it's worth, I ended up using Spring's TaskExecutor API, which has the advantage of letting me choose which implementation to use. Works like a charm.
The interface was close enough to WorkManager so that I had very little changes to make in the code.
精彩评论