Tuesday, 27 August 2013

Does a Synchronous Queue create a thread on each offer/put?

Does a Synchronous Queue create a thread on each offer/put?

I can not understand how the Synchronous Queue works.
I understand that the idea is that the handover of tasks is to threads
directly but the constructor does not have a bound e.g max number of
threads like the other APIs.
So when a put or offer is done it is essentially passed to another thread
or not?
So if I do e.g. 100 put it will be passed to 100 threads?
I tried to read the source code but could not figure out what happens. It
seems to create a linked list of nodes where each node encapsulates a
thread but how this list is maintained e.g. expand/shrink etc and how the
treads run the tasks is not clear to me.
So does this list expand as we offer tasks? And as a result the consumer
threads (waiters) increases constantly?
And are any of these reused? Or just execute something and stop?

No comments:

Post a Comment