-
1. Re: Long-lived MDBs and application server shutdown
stevenpeh Feb 28, 2005 4:00 AM (in response to twalsh2)umm... just a suggestion, how bout a shutdown MDB that sets a static flag somewhere or better yet execute an interface callback method which your long running MDBs implement to notify them of the shutdown even... of course you'd have to register a shutdown hook with the container to trigger the shutdown MDB (shutdown hooks would be app container specific).
If you're using the interface callbacks, you can probably have a singleton register the long running MDBs as listeners and the shutdown hook use the singleton to notify registered listeners of shutdown event.
Just a suggestion, havent really tried it myself... dont really believe in long running MDBs ;-) -
2. Re: Long-lived MDBs and application server shutdown
twalsh2 Feb 28, 2005 10:16 AM (in response to twalsh2)A couple of questions on your suggestions:
>just a suggestion, how bout a shutdown MDB that sets a static flag
>somewhere or better yet execute an interface callback method which your
>long running MDBs implement to notify them of the shutdown even
1) How would you go about getting a reference to all currently executing MDBs so you could call a method they implement? I don't see any obvious reference to them in the JNDI tree.
>Just a suggestion, havent really tried it myself... dont really believe
>in long running MDBs ;-)
2) Within a J2EE context, what component would you use to represent a potentially long-lived and asynchronous background task? I suppose a JMX MBean could be used, but I am trying to limit the app-server specific components as much as possible. -
3. Re: Long-lived MDBs and application server shutdown
stevenpeh Feb 28, 2005 10:07 PM (in response to twalsh2)
>just a suggestion, how bout a shutdown MDB that sets a static flag
>somewhere or better yet execute an interface callback method which your
>long running MDBs implement to notify them of the shutdown even
1) How would you go about getting a reference to all currently executing MDBs so you could call a method they implement? I don't see any obvious reference to them in the JNDI tree.
Well, like i said, you'd use a singleton. Then for in each MDB's onMessage method, there will be something like this to register and deregister itself...public void MyMDB implements MessageDrivenBean, MessageListener, MyShutdownEventListener public void onMessage(Message msg){ // register myself MyShutdownSingleton.getInstance().addShutdownListener(this); // do my long running task .... // if i complete my long running task and no shutdown event yet, then // deregister myself myShutdownSingleton.getInstance().removeShutdownListener(this); } // implement my shutdown event code here public void myShutdownEvent(){ ... }
In your shutdown hook, you'd just call the MyShutdownSingleton.fireShutdownEvent() method which basically iterates through all registered listeners and call their myShutdownEvent method.
Anyway like i said, havent tried this in a J2EE context. Interface callbacks are quite common when developing Swing apps. Just an idea thrown in for you to try if you want, use at your own risk. Good luck.
Cheers.