Discussion:
Using Runtime.addShutdownHook with WebSphere.
(too old to reply)
Pratap Das
2005-01-19 20:42:45 UTC
Permalink
I'm wondering if I can use a Runtime.addShutdownHook safely in a
Websphere EJB container to call a cleanup routine.

Basically, I have an EAR file with a session bean wrapping a
third-party product. Now, this third party product needs to be
"initialized" once during the life-time of the EAR file (does some
pre-fetching of data into a in-memory cache). Similarly, before the EAR
file is shutdown I also need to perform a "cleanup" call on this third
party product so that this cache is cleared up and any open database
connections are closed properly. The third party cache is being cached
in a static variable (read-only from client's perspective).

What would be the best way to do this? I was reading up on "pre-fetch"
best practices and the suggestions indicated that I should use an
"initializer" servlet packaged along with my session ejb - this
servlet's init() method would make the first "initialize" call while
the EAR file is started in WAS. This seems to work.

Now, I need to similarly call cleanup when the EAR file is being
shutdown. I was thinking of putting this call in my servlet's destroy -
however, I'm don't think this is a safe option since the servlet
container could destroy the initializer servlet any time. I already
have it on a finalizer (on the class containing the static variable) -
but this is not guaranteed to be called either when JVM shuts down.

I'm wondering if I should attach a shutdown hook object that would
explicitly call cleanup when the class containing the static variable
is destroyed.

Can anyone help me understand what is the best way to go about this
intialize/cleaup routine in an WebSpehere container (WAS). I'm using
WSAD 5.1.3 and WAS 5.1.1.

Thanks much in advance!
--Das
cnpeyton
2005-01-19 21:01:09 UTC
Permalink
I would also look at custem services in WebSphere 5. Custom services
allow you to put in hooks at the startup of your application server and
the shutdown of your application server. I have used them a couple of
times and they work very nicely. The only thing to be careful of is
the classloader is different the the application classloader. You have
to extend a WAS class to register a custom services.

Go to the info center,
http://publib.boulder.ibm.com/infocenter/ws51help/index.jsp , search on
custom service and check out the first search result. The have an
explanantion and a link to developing customer services.

I think they also have another concept called startup beans, but it is
only available in EE.

Chris
Pratap Das
2005-01-20 05:52:27 UTC
Permalink
Post by cnpeyton
I would also look at custem services in WebSphere 5. Custom services
allow you to put in hooks at the startup of your application server and
the shutdown of your application server. I have used them a couple of
times and they work very nicely. The only thing to be careful of is
the classloader is different the the application classloader. You have
to extend a WAS class to register a custom services.
Thanks for this info. I took a look at the custom services and found
that coupled with the classloader issue you mentioned, it also has some
restrictions unfortunately:
- No work is dispatched into the server instance until all custom
service initialize methods return. (So, if I need to initialize a class
which lives on the server classloader, I can't do that)
- Execution of standard J2EE code (client code, servlets, enterprise
beans) is not supported.

The classloader issue is the biggest problem since I would need to
access the initialized cache from my application.
Post by cnpeyton
Go to the info center,
http://publib.boulder.ibm.com/infocenter/ws51help/index.jsp , search on
custom service and check out the first search result. The have an
explanantion and a link to developing customer services.
I think they also have another concept called startup beans, but it is
only available in EE.
Yeah, I saw this starup beans approach and had explored it - however we
use the standard WAS not the EE.
I appreciate your pointers!
Thanks,
--Das
Post by cnpeyton
Chris
Loading...