Rahul Ramamoorthy
Rahul Ramamoorthy

Reputation: 31

Setting Priority in Thread scheduler for threads which have waited and notified

I have a series of producer and consumer threads. In consumer thread I have lock.wait() function to stop execution if there is no data in queue. When data is produced in producer thread, lock.notify() is called and consumer thread comes out of waiting state and moved to thread scheduler for acquiring the lock. When the notifier producer thread releases the lock, thread scheduler selects a random thread for processing(which can also be a another producer thread but I want it to give lock to this waited thread). My problem is, is there a way for these waited and notified threads to get higher priority to acquire the lock soon instead of Thread scheduler treating as a normal thread. I have tried Thread.currentthread.setPriority and it doesn't work :(

Upvotes: 1

Views: 171

Answers (1)

Lalit Mehra
Lalit Mehra

Reputation: 1273

Highest priority thread will always get the CPU time is not guaranteed. The JVM may choose to run a lower priority thread at times.

Check out this link http://journals.ecs.soton.ac.uk/java/tutorial/java/threads/priority.html

Upvotes: 1

Related Questions