-
1. Re: How to get a WorkManager from a Bean
hannes.koller Mar 27, 2006 4:32 AM (in response to cmalo)Hi,
I know your post was a long time ago. I was asking myself the same Question today, and I could not find a simple example of this..so it took me a rather long time to come up with a solution..I thought it could not hurt to post it here...//get MBean Server MBeanServer server = MBeanServerLocator.locateJBoss(); //get WorkManager ObjectName objectName = new ObjectName("jboss.jca:service=WorkManager"); JBossWorkManagerMBean jwm = (JBossWorkManagerMBean) MBeanServerInvocationHandler.newProxyInstance(server,objectName,JBossWorkManagerMBean.class,false); WorkManager wm = jwm.getInstance(); //schedule Work for Execution wm.scheduleWork(new SomeWork());
Note that there is a difference between scheduleWork() (call returns immediately) doWork(call returns when work is finished) and startWork() (call returns when work is started).
Btw. If there is anything wrong with this solution, I would appreciate it if someone could tell me. TIA :) -
2. Re: How to get a WorkManager from a Bean
oglueck Jan 5, 2007 9:59 AM (in response to cmalo)As there is no documentation on WorkManager at all it would be very nice of the JBoss people to at least respond to forum postings. Can anybody tell me in what kind of security and transaction context the work thread will run? E.g. will the task have to authenticate for EJB calls?
-
3. Re: How to get a WorkManager from a Bean
weston.price Jan 5, 2007 12:38 PM (in response to cmalo)The WorkManager is reserved for ResourceAdapters and is not applicable to other EE components (Servlets/EJB). At this point, there is no generalized notion of a WorkManagement API across the entire application environment. A JSR has been submitted but there is no work currently being done on it.
-
4. Re: How to get a WorkManager from a Bean
madhav_avm Jan 29, 2007 3:50 AM (in response to cmalo)I have read that we can do parallel processing in J2EE Container using WorkManger API(JSR 237).But as per weston comment below,In Jboss Workmanager API is only for resource adapters.Can anyone please suggest me how we can do parallel processing in JBoss J2EE Container.
-
5. How to get a WorkManager instance?
lpmon Jan 31, 2007 11:18 AM (in response to cmalo)Seems like there should be a JNDI/context-based lookup to get the WorkManager.
I want to launch some worker threads. The page below and other reading suggests a lookup can be done:
http://www.java-tips.org/java-ee-tips/enterprise-java-beans/j2ee-connector-architecture-1.5.html
....Maybe just not in JBoss yet.
Do I get a work manager using the methods in the previous posts? -
6. Re: How to get a WorkManager from a Bean
weston.price Jan 31, 2007 11:27 AM (in response to cmalo)Again, the WorkManager is reserved for ResourceAdapters (ie JCA deployments) it is not available via JNDI or to any other type of application component.
The documentation link you posted is relevant to JCA not as a general solution for all application components.
Technically, there is nothing to prevent you from getting the WorkManager via JMX (as per the example below), but this is not standard and not portable. In other words, you shouldn't really be doing this. A generalized WorkManagement API has been submitted as a JSR (237)
http://jcp.org/en/jsr/detail?id=237
However, it is currently in limbo right now due to legal disputes between the major vendors involved. -
7. Re: How to get a WorkManager from a Bean
oglueck Jan 31, 2007 11:31 AM (in response to cmalo)Portability is not much of an issue for me. We are quite committed to using JBoss, and moving to another appserver would mean lots of man-years of work anyway. So a JBoss-only solution that is available now is more welcome than a portable one that is not available. Anyway, JBoss specific code can always be wrapped behind a custom interface if portability is a real concern.
-
8. Re: How to get a WorkManager from a Bean (worker threads)
lpmon Jan 31, 2007 11:35 AM (in response to cmalo)Thank You Weston.
Then let me ask the more generic question:
What is the recommendation to start/manage background worker threads in JBoss 4.0.x?
Using JMS for a long running process seems to be discouraged (like 5 minutes of background work)
I can implement a Runnable/Thread class and manage it myself but per J2EE protocol this is not recommended. Threads are supposed to be managed by the app server.
Thanks in advance! -
9. Re: How to get a WorkManager from a Bean
weston.price Jan 31, 2007 11:43 AM (in response to cmalo)Best of luck ;-)
As far as the
Can anybody tell me in what kind of security and transaction context the work thread will run?
The answer is that it will be unspecified being that the WorkManager API is meant to be consumed solely from a ResourceAdapter which would have it's own transaction/security context. In other words, it is unknown and there are no guarantees because this is a non standard use of the API. -
10. Re: How to get a WorkManager from a Bean
oglueck Jan 31, 2007 11:47 AM (in response to cmalo)So we're left with managing our own threads? To be safe, I suppose we should perform a JAAS logon, manage a client transaction and use remote interfaces only, basically acting like an application client.
-
11. Re: How to get a WorkManager from a Bean
weston.price Jan 31, 2007 11:47 AM (in response to cmalo)
What is the recommendation to start/manage background worker threads in JBoss 4.0.x?
There is nothing to prevent you from developing a custom MBean that uses threads or a thread pool to preform background tasks. Simple wrap your Runnable/Thread stuff in an MBean and that's that. Also, JMX is nice for configuration/management as well. This would be my suggestion.
You could develop a custom JCA adapter that's sole purpose is to give EJB and Servlets access to the WorkManagement API but this is a bit heavy when a simple MBean would really suffice. -
12. Re: How to get a WorkManager from a Bean
michele.curioni Apr 27, 2007 6:59 AM (in response to cmalo)Hi there,
has any progress been made in JBoss on this front?
Other vendors allow to use Workmanager from every component.
It would be good to have the same feature in JBoss.
Thanks,
Michele -
13. Re: How to get a WorkManager from a Bean
kevinpauli Jun 27, 2007 5:13 PM (in response to cmalo)+1
-
14. Re: How to get a WorkManager from a Bean
chrismeadows Jan 31, 2008 5:24 AM (in response to cmalo)+1
But until then, the MBean approach is a good approach.
If, however, your system is mostly asynchronous/event driven, then J2EE isn't really the way to proceed; you may want to use the JBoss JSLEE container instead, http://labs.jboss.com/mobicents