Re: Thread synchronization question: queued or not?
Posted By:
Marian_Olteanu
Posted On:
Thursday, February 28, 2002 06:23 AM
Quote from API documentation, java.lang.Object , method notify() :
Wakes up a single thread that is waiting on this object's monitor. If any threads are waiting on this object, one of them is chosen to be awakened. The choice is arbitrary and occurs at the discretion of the implementation.
Re: Thread synchronization question: queued or not?
Posted By:
Bozidar_Dangubic
Posted On:
Wednesday, January 2, 2002 06:16 AM
if you need it as a queue, write it as a queue. create a ThreadPool class which handles your worker threads for you. you can also download the code for this from the web, many have already been written. this way, you are controlling how threads are allocated and in which order and you are not depending on the JVM to implement thread pooling for you. it also allows you to change priority policy later (from FIFO to say LIFO) in a single location.
Re: Thread synchronization question: queued or not?
Posted By:
Terry_Laurenzo
Posted On:
Tuesday, January 1, 2002 09:44 AM
I looked briefly for the relevant portion in the JVM spec, but I couldn't find it. However, I am 99% sure that the ordering that you are observing is not mandated by the spec. It is therefore subject to change and should not be relied on(even using a multi-processor machine instead of a single processor one could affect it). I too have observed this "queue-like" behavior of waiting threads on the win32 sun VMs, but I cannot speak for the others.
Without knowing what you are trying to accomplish that requires this ordering, I really cannot spell out a solution. There are a number of ways to ensure ordering, varying from simple(and usually inefficient) to complex.