queueConnection.start();
}
public void testTemporaryQueueConsumer() throws Exception {
final int NUMBER = 20;
final SynchronizedInt count = new SynchronizedInt(0);
for (int i = 0;i < NUMBER;i++) {
Thread thread = new Thread(new Runnable() {
public void run() {
try {
QueueConnection connection = createConnection();
QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createTemporaryQueue();
QueueReceiver consumer = session.createReceiver(queue);
connection.start();
if (count.increment() >= NUMBER){
synchronized(count){
count.notify();
}
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
});
thread.start();
}
int maxWaitTime = 20000;
synchronized (count) {
long waitTime = maxWaitTime;
long start = System.currentTimeMillis();
while (count.get() < NUMBER) {
if (waitTime <= 0) {
break;
}
else {
count.wait(waitTime);
waitTime = maxWaitTime - (System.currentTimeMillis() - start);
}
}
}
assertTrue("Unexpected count: " + count, count.get() == NUMBER);
}