We have a task that may run for as little as 2 minutes or as long as 2 days. It will spawn a series of child processes that do most of the work, waiting for each child to finish before starting the next. While it is running, we need to be able to report status (either polling or monitoring a JMS topic is fine) and the user needs to be able to stop it before it finishes. We may want to run this under an app server (probably WebLogic).
What's the best approach for this? MDBs and session beans both seem like they are not the best for this. For background, here are some related topics from this forum: This topic says there is no built-in solution, which could imply that we should just create a custom class that starts a new Thread. This topic indicates that a session bean with a transaction attribute of NotSupported would be good.
Well this may seem bold, but the "Long Running Process" post talks about a ClassCastException, iow does not really do much for the topic of this post. When I sat down to write my primary application, a threading approach evolved even with limited coding and logic skills. Though given brief but real testing, it's performance was clearly acceptable and I would wonder about any aleady-written code as I have had a clear pattern emerge of having such code run great for a while, then one is forced to 'download the latest software' - which in short means a lot to a great many folks.
The overall design pattern is extremely simple:
1. Make all vars volatile, whether anyone likes it or not.
2. If you have to synch() on more than one object, re-design from top down.
3. Entry is by synchronized, static -> usually called a static factory method.
4. Communication by shared vars, which must be objs.
5. Lots of test first development, followed by heavy loading in alpha.
6. Extreme Programming has several tools to offer.
7. The raw power of the platform has to be taken into design eval.
8. You have to monitor the total thread count somehow.
[ December 08, 2007: Message edited by: Nicholas Jordan ]
"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
I would suggest to use WebLogic timer. You can schedule the timers in startup class and cancel the same in shutdown class. Status communication and pause/stop communications can be through a JMS queue.