This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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
Author

Need a design idea.

Krishnaa Kumar
Greenhorn

Joined: May 05, 2011
Posts: 25
Hi.,
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
Greenhorn

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
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

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


SCJP, SCWCD.
|Asking Good Questions|
 
GeeCON Prague 2014
 
subject: Need a design idea.