Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Gerald Rubin
Can I receive a message just before I am being replaced in a re-deploy
December 8, 2012 11:29 AM
Answer

Gerald Rubin

Rank: Junior Member

Posts: 59

Join Date: October 23, 2011

Recent Posts

[LR 6.1.0 CE GA1] One of my beans acts as a static data cache. It is injected into a number of other beans (all in the same war). The static cache loads users' data from the database and holds it in memory for quick access.

I start a thread in this data cache that runs every 30 minutes and deletes from memory any user's data that hasn't been touched in 90 minutes (both numbers are configurable).

When I redeploy the war containing this data cache and all the portlets that inject it, a new instance of the data cache is started (with an empty HashMap of user data), but the old threads are not killed. Is there any mechanism that I can use to know that I should kill threads before I am about to be replaced?

I guess if there isn't I could kill my threads whenever there is no data in the bean's HashMap (it all having been cleaned out), assuming these old threads are still running every 30 minutes and probably accessing some HashMap. But were those threads keeping some heap memory from being deleted? Beats me.

So, to summarize: I think my data cache bean is being kept alive even after it is redeployed while its threads wake up on schedule, look at some collection and go back to sleep.

I hope this made sense to someone. As you can see, it barely does to me.

Thanks.
Bijan Vakili
RE: Can I receive a message just before I am being replaced in a re-deploy
December 8, 2012 1:28 PM
Answer

Bijan Vakili

Rank: Expert

Posts: 354

Join Date: March 10, 2009

Recent Posts

As part of the Portlet 2.0 Lifecycle, the destroy() method allows such cleanup work to be done.
See section "PLT.5.2.3 End of Service" in JSR 286 spec.