Search in sources :

Example 1 with ActiveMQThreadPoolExecutor

use of org.apache.activemq.artemis.utils.ActiveMQThreadPoolExecutor in project activemq-artemis by apache.

the class ActiveMQServerImpl method initializeExecutorServices.

/**
 * Sets up ActiveMQ Artemis Executor Services.
 */
private void initializeExecutorServices() {
    /* We check to see if a Thread Pool is supplied in the InjectedObjectRegistry.  If so we created a new Ordered
       * Executor based on the provided Thread pool.  Otherwise we create a new ThreadPool.
       */
    if (serviceRegistry.getExecutorService() == null) {
        ThreadFactory tFactory = AccessController.doPrivileged(new PrivilegedAction<ThreadFactory>() {

            @Override
            public ThreadFactory run() {
                return new ActiveMQThreadFactory("ActiveMQ-server-" + this.toString(), false, ClientSessionFactoryImpl.class.getClassLoader());
            }
        });
        if (configuration.getThreadPoolMaxSize() == -1) {
            threadPool = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), tFactory);
        } else {
            threadPool = new ActiveMQThreadPoolExecutor(0, configuration.getThreadPoolMaxSize(), 60L, TimeUnit.SECONDS, tFactory);
        }
    } else {
        threadPool = serviceRegistry.getExecutorService();
        this.threadPoolSupplied = true;
    }
    this.executorFactory = new OrderedExecutorFactory(threadPool);
    if (serviceRegistry.getIOExecutorService() != null) {
        this.ioExecutorFactory = new OrderedExecutorFactory(serviceRegistry.getIOExecutorService());
    } else {
        ThreadFactory tFactory = AccessController.doPrivileged(new PrivilegedAction<ThreadFactory>() {

            @Override
            public ThreadFactory run() {
                return new ActiveMQThreadFactory("ActiveMQ-IO-server-" + this.toString(), false, ClientSessionFactoryImpl.class.getClassLoader());
            }
        });
        this.ioExecutorPool = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), tFactory);
        this.ioExecutorFactory = new OrderedExecutorFactory(ioExecutorPool);
    }
    /* We check to see if a Scheduled Executor Service is provided in the InjectedObjectRegistry.  If so we use this
       * Scheduled ExecutorService otherwise we create a new one.
       */
    if (serviceRegistry.getScheduledExecutorService() == null) {
        ThreadFactory tFactory = AccessController.doPrivileged(new PrivilegedAction<ThreadFactory>() {

            @Override
            public ThreadFactory run() {
                return new ActiveMQThreadFactory("ActiveMQ-scheduled-threads", false, ClientSessionFactoryImpl.class.getClassLoader());
            }
        });
        scheduledPool = new ScheduledThreadPoolExecutor(configuration.getScheduledThreadPoolMaxSize(), tFactory);
    } else {
        this.scheduledPoolSupplied = true;
        this.scheduledPool = serviceRegistry.getScheduledExecutorService();
    }
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ActiveMQThreadFactory(org.apache.activemq.artemis.utils.ActiveMQThreadFactory) OrderedExecutorFactory(org.apache.activemq.artemis.utils.actors.OrderedExecutorFactory) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) SynchronousQueue(java.util.concurrent.SynchronousQueue) ActiveMQThreadFactory(org.apache.activemq.artemis.utils.ActiveMQThreadFactory) ActiveMQThreadPoolExecutor(org.apache.activemq.artemis.utils.ActiveMQThreadPoolExecutor) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ActiveMQThreadPoolExecutor(org.apache.activemq.artemis.utils.ActiveMQThreadPoolExecutor)

Aggregations

ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 SynchronousQueue (java.util.concurrent.SynchronousQueue)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 ActiveMQThreadFactory (org.apache.activemq.artemis.utils.ActiveMQThreadFactory)1 ActiveMQThreadPoolExecutor (org.apache.activemq.artemis.utils.ActiveMQThreadPoolExecutor)1 OrderedExecutorFactory (org.apache.activemq.artemis.utils.actors.OrderedExecutorFactory)1