Pratap Das
2005-01-19 20:42:45 UTC
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
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