If I have a common thread pool that queues runnable tasks and the runnable task is the same object every time.
What happens when it reaches a block of code (within the runnable task) that has a synchronised lock? and say 5 threads are waiting on the same lock?
When it unlocks, is the synchronised block a queue line waiting to be executed and new threads join the queue, or whoever managed to grab the block first?
If there isn’t a queue line, assuming I want an ordered execution, what is the best method to do so?
synchronized blocks do not have any defined order. you can use a
java.util.concurrent.locks.ReentrantLockwith “fair” locking to achieve the same affect as a synchronized block, but with guaranteed ordering.