Java Code Examples for org.apache.activemq.ActiveMQConnectionFactory#setMaxThreadPoolSize()

The following examples show how to use org.apache.activemq.ActiveMQConnectionFactory#setMaxThreadPoolSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConnectionFactory.java    From hazelcast-simulator with Apache License 2.0 5 votes vote down vote up
public Connection newConnection(String brokerURL, ExceptionListener exceptionListener) throws JMSException {
        String finalBrokerURL = toUrl(brokerURL);

        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(finalBrokerURL);

        // to speed things up; don't wait till it is on the socket buffer.
        // http://activemq.apache.org/async-sends.html
        connectionFactory.setUseAsyncSend(true);

        // authentication stuff.
        connectionFactory.setUserName(username);
        connectionFactory.setPassword(password);
        // we want to consume the least amount of resources possible. And there will be very low volume traffic.

        connectionFactory.setMaxThreadPoolSize(MAX_THREAD_POOL_SIZE);
        //
//        connectionFactory.setRejectedTaskHandler(new  RejectedExecutionHandler() {
//            public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
//                try {
//                    executor.getQueue().put(r);
//                } catch (InterruptedException var4) {
//                    throw new RejectedExecutionException(var4);
//                }
//            }
//        });

        Connection connection = connectionFactory.createConnection();
        connection.setExceptionListener(exceptionListener);
        connection.start();
        return connection;
    }