File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Threads and Synchronization and the fly likes Need a design idea. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Need a design idea." Watch "Need a design idea." New topic

Need a design idea.

Krishnaa Kumar

Joined: May 05, 2011
Posts: 25
I Have a store and there exists many objects. Periodically i need to clean the store by dispatching the objects in it to another store.
When Iam cleaning the store, some of its object might be already in use (Other threads might be using the object to update its values).
I Can't wait until the other thread release the reference since, its a continuous process. So, some other object might now get Already in Use stage.
I cant't make the Store synchronized since threads creating new objects should not made to wait.

I need some design ideas to achieve proper cleaning of store.
Vladimir Ozerov

Joined: Sep 27, 2011
Posts: 14
One pretty straightforward solution is to create a blocking queue.
When any thread need to work with an object, it takes object from the queue and when work is finished it puts object back to the queue.
And your dispathcer thread will do the following: fetch object from the queue, then move it to another store, but not return it back to the queue.
Amit Ghorpade

Joined: Jun 06, 2007
Posts: 2846

Looks like a threads question to me, moving to its forum

|Asking Good Questions|
I agree. Here's the link:
subject: Need a design idea.
It's not a secret anymore!