I have a simple program to generate input for CRC32, which output a number ending in 123456 (in hexadecimal format). It works in a workflow (the next step is to create multiple workflows). The worker thread sends the results to the q queue.
import java.util.*; import java.util.concurrent.*; import java.util.zip.*; class A { static final BlockingQueue<List<Byte>> q = new LinkedBlockingQueue<List<Byte>>(); static { new Thread() { public void run() { System.out.println("worker thread starting"); int len = 1; byte[] a = new byte[32]; for (int i =0; i < 32; i++) a[i]=-128; while (true) { CRC32 crc = new CRC32(); crc.update(a, 0, len); long x = crc.getValue(); if ((x & 0xffffff) == 0x123456) { System.out.println("HA " + Arrays.toString(a) + "; " + x); List<Byte> l = new LinkedList<Byte>(); for (int i = 0; i < a.length; i++) l.add(a[i]); System.out.println("A"); q.add(l); System.out.println("B");
For some reason it gets stuck:
$ javac A.java && java A worker thread starting HA [-49, 72, 73, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128, -128]; 1376924758 A
The worker thread is explicitly blocked when sent to the queue ( q.add(l) ), otherwise, "B" will be printed to the console. If I comment on a line reading from a queue ( while (q.size() != amount) ), it no longer gets stuck. I thought this behavior is not possible for an unlimited queue (if it does not already have 2147483647 elements). This is not a SynchronousQueue , so queuing should work regardless of whether any thread is receiving from it. Actually this behavior seems to be the opposite of SynchronousQueue : sending only works if there is no receiver .
Why is the workflow blocked when trying to queue?