You can't split it in half in general, I mean to split in half this queue must have a size at each point in time. And while CLQ
does have a size()
method, it's documentation is pretty clear that this size requires O(n)
traversal time and because this is a concurrent queue
it's size might not be accurate at all (it is named concurrent
for a reason after all). The current Spliterator
from CLQ
splits it in batches from what I can see.
If you want to split it in half logically and process the elements, then I would suggest moving to some Blocking
implementation that has a drainTo
method, this way you could drain the elements to an ArrayList
for example, that will split much better (half, then half again and so on).
On a side note, why would you want to do the processing in different threads yourself? This seems very counter-intuitive, the Spliterator
is designed to work for parallel streams. Calling trySplit
once is probably not even enough - you have to call it until it returns null
... Either way doing these things on your own sounds like a very bad idea to me.