This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 2716

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.
Similar Threads
NX: Grow File Size Puzzle
Using Threads
Using Soft references for cache
EJB3 -> Best optimizzed way for bulk insert ?
how to find the variable get updated by simultaneous threads