• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Queing of several request threads

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic