How to fire off a asych thread in a web application, and gaurantee only 1 thread fires?

Posted by Blankman on Stack Overflow See other posts from Stack Overflow or by Blankman
Published on 2010-05-19T18:11:20Z Indexed on 2010/05/19 19:10 UTC
Read the original article Hit count: 225

Filed under:
|

I want to cache a object in memory. Regenerating the object when the cache expires is fairly expensive, so I want to do the following:

When the cache is "about" to expire, I want to fire off a asychronous thread that will go and rebuild the object and then reset the cache.

One thing I am worry about is multiple threads firing to fetch the object to cache, I only want a single thread doing this, realizing many people will be hitting the website.

This might not be the best use case to do this, but I want to know how to do this sort of thing.

© Stack Overflow or respective owner

Related posts about java

Related posts about threads