@Test(timeout=120000)
public void demo() throws JMSException, InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean done = new AtomicBoolean(false);
final PooledConnectionFactory pooled = new PooledConnectionFactory();
pooled.setConnectionFactory(new ActiveMQConnectionFactory("vm://localhost?create=false"));
pooled.setMaxConnections(2);
pooled.setExpiryTimeout(10L);
//pooled.start();
Thread[] threads = new Thread[10];
for (int i = 0; i < threads.length; i++) {
threads[i] = new Thread(new Runnable() {
@Override
public void run() {
while (!done.get() && latch.getCount() > 0) {
try {
final PooledConnection pooledConnection = (PooledConnection) pooled.createConnection();
if (pooledConnection.getConnection() == null) {
LOG.info("Found broken connection.");
latch.countDown();
}
pooledConnection.close();