Example usage for javax.jms XASession createQueue

List of usage examples for javax.jms XASession createQueue

Introduction

In this page you can find the example usage for javax.jms XASession createQueue.

Prototype

Queue createQueue(String queueName) throws JMSException;

Source Link

Document

Creates a Queue object which encapsulates a specified provider-specific queue name.

Usage

From source file:org.apache.activemq.store.jdbc.JDBCCleanupLimitedPoolTest.java

@Test
public void testNoDeadlockOnXaPoolExhaustion() throws Exception {
    final CountDownLatch done = new CountDownLatch(1);
    final CountDownLatch doneCommit = new CountDownLatch(1000);

    final ActiveMQXAConnectionFactory factory = new ActiveMQXAConnectionFactory(
            broker.getTransportConnectorByScheme("tcp").getPublishableConnectString());

    ExecutorService executorService = Executors.newCachedThreadPool();
    // some contention over pool of 2
    for (int i = 0; i < 3; i++) {
        executorService.execute(new Runnable() {
            @Override/*from  ww  w  . ja  v a  2s .co m*/
            public void run() {
                try {
                    ActiveMQXAConnection conn = (ActiveMQXAConnection) factory.createXAConnection();
                    conn.start();
                    XASession sess = conn.createXASession();
                    while (done.getCount() > 0 && doneCommit.getCount() > 0) {
                        Xid xid = createXid();
                        sess.getXAResource().start(xid, XAResource.TMNOFLAGS);
                        MessageProducer producer = sess.createProducer(sess.createQueue("test"));
                        producer.send(sess.createTextMessage("test"));
                        sess.getXAResource().end(xid, XAResource.TMSUCCESS);
                        sess.getXAResource().prepare(xid);
                        sess.getXAResource().commit(xid, false);
                        doneCommit.countDown();
                    }

                    conn.close();

                } catch (Exception ignored) {
                    ignored.printStackTrace();
                }
            }
        });
    }

    executorService.execute(new Runnable() {
        @Override
        public void run() {
            try {
                while (!done.await(10, TimeUnit.MILLISECONDS) && doneCommit.getCount() > 0) {
                    jdbcPersistenceAdapter.cleanup();
                }
            } catch (Exception ignored) {
            }

        }
    });

    executorService.shutdown();
    boolean allComplete = executorService.awaitTermination(40, TimeUnit.SECONDS);
    done.countDown();
    assertTrue("all complete", allComplete);
    executorService.shutdownNow();

    assertTrue("xa tx done", doneCommit.await(10, TimeUnit.SECONDS));
}