Java - multithreaded access to a local value store which is periodically cleared

Posted by Telax on Stack Overflow See other posts from Stack Overflow or by Telax
Published on 2012-07-08T08:43:00Z Indexed on 2012/07/08 9:15 UTC
Read the original article Hit count: 148

Filed under:
|
|

I'm hoping for some advice or suggestions on how best to handle multi threaded access to a value store.

My local value storage is designed to hold onto objects which are currently in use. If the object is not in use then it is removed from the store.

A value is pumped into my store via thread1, its entry into the store is announced to listeners, and the value is stored. Values coming in on thread1 will either be totally new values or updates for existing values.

A timer is used to periodically remove any value from the store which is not currently in use and so all that remains of this value is its ID held locally by an intermediary.

Now, an active element on thread2 may wake up and try to access a set of values by passing a set of value IDs which it knows about. Some values will be stored already (great) and some may not (sadface). Those values which are not already stored will be retrieved from an external source.

My main issue is that items which have not already been stored and are currently being queried for may arrive in on thread1 before the query is complete.

I'd like to try and avoid locking access to the store whilst a query is being made as it may take some time.

© Stack Overflow or respective owner

Related posts about java

Related posts about multithreading