• Post Reply Bookmark Topic Watch Topic
  • New Topic

Queing of several request threads  RSS feed

 
Praveen Balaji
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I need to implement a Request queue with the following problem description:
1. I have a connection pool that will notify when a free connection is available. Concurrent requests wait in a queue for this notification if the pool doesnot have sufficient connections.
2. Requests have a timeout. While waiting for the connection, some of the requests may timeout if they donot receive a free connection in the given time.
Could anyone point me to tips on how I can implement this? If I am able to make the request threads "sleep" for a given time, my problem is 80% solved.
Thanks in advance,
Praveen.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me quote your problem description back at you, with subtle modifications
1. I have a connection pool that will java.lang.Object.notify() when a free connection is available. Concurrent requests wait in the wait set for this notification if the pool does not have sufficient connections.
2. Requests java.lang.Object.wait(timeout) only for a limited period of time. While waiting for the connection, some of the requests may timeout if they do not receive a free connection in the given time.
Hope this helps. If this is too cryptic, please accept my apologies; just ask and I'll try to help.
- Peter
 
Praveen Balaji
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Thanks for replying. I am not exactly using java.lang.Object.notify() because it does not assure which thread it's going to notify. I need to maintain the queue order. I have attached a code snippet that might explain the exact problem I am trying to solve.


Thanks in advance,
Praveen
 
Praveen Balaji
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This is a simple class that explains my problem.

What happens here is the interrupted flag is set to true even before the thread goes to sleep. So, when the method of the thread t1 is called, it exits without sleeping.
Now my problem has boiled down to:
How do i set the Thread state back to not interrupted after it has interrupted?
I dont want to mess with client threads.
Thanks in advance for help..
praveen
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!