@Setup public synchronized void setup() { for (int i = 0; i < MAX_THREAD_COUNT; i++) { responseQueues[i] = new OneToOneConcurrentArrayQueue<>(RESPONSE_QUEUE_CAPACITY); } values = new Integer[burstLength]; for (int i = 0; i < burstLength; i++) { values[i] = -(burstLength - i); } consumerThread = new Thread( () -> { while (true) { final Integer value = sendQueue.poll(); if (null == value) { if (!running.get()) { break; } } else { final int intValue = value; if (intValue >= 0) { final Queue<Integer> responseQueue = responseQueues[value]; while (!responseQueue.offer(value)) { // busy spin } } } } }); consumerThread.setName("consumer"); consumerThread.start(); }
@TearDown public synchronized void tearDown() throws Exception { running.set(false); consumerThread.join(); }