File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Queing of several request threads Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Queing of several request threads" Watch "Queing of several request threads" New topic
Author

Queing of several request threads

Praveen Balaji
Ranch Hand

Joined: Jun 17, 2001
Posts: 60
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

Joined: Apr 20, 2000
Posts: 3252
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

Joined: Jun 17, 2001
Posts: 60
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

Joined: Jun 17, 2001
Posts: 60
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
 
 
subject: Queing of several request threads
 
Threads others viewed
Socket Server only processing one request, then it just queues them up
How do you execute new code in an existing Thread?
JNDI lookup for DataSource
Any reason to have more MaxThreads than # of CPU Cores ?
Putting a time out on individual threads inside ThreadPoolExecutor
Two Laptop Bag