• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need a design idea.

 
Krishnaa Kumar
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like a threads question to me, moving to its forum
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic