Search in sources :

Example 1 with PrioritizedRunnable

use of alma.ACS.jbaci.PrioritizedRunnable in project ACS by ACS-Community.

the class CharacteristicComponentImpl method execute.

/**
	 * Execute action. 
	 * If the maximum pool size or queue size is bounded,
	 * then it is possible for incoming execute requests to block. 
	 * <code>BACIExecutor</code> uses default 'Run' blocking policy: 
	 * The thread making the execute request runs the task itself. This policy helps guard against lockup. 
	 * @param action	action to execute.
	 * @return <code>true</code> on success.
	 */
public boolean execute(PrioritizedRunnable action) {
    try {
        if (threadPool == null) {
            // TODO make PriorityBlockingQueue bounded!!! (to MAX_REQUESTS)
            // TODO should I use PooledExecutorWithWaitInNewThreadWhenBlocked...?
            threadPool = new ThreadPoolExecutor(MAX_POOL_THREADS, MAX_POOL_THREADS, 1, TimeUnit.MINUTES, new PriorityBlockingQueue<Runnable>(MAX_REQUESTS, new PrioritizedRunnableComparator<Runnable>()), m_containerServices.getThreadFactory());
            threadPool.allowCoreThreadTimeOut(true);
        }
        threadPool.execute(action);
        return true;
    } catch (Throwable th) {
        return false;
    }
}
Also used : PrioritizedRunnable(alma.ACS.jbaci.PrioritizedRunnable) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) PriorityBlockingQueue(java.util.concurrent.PriorityBlockingQueue)

Aggregations

PrioritizedRunnable (alma.ACS.jbaci.PrioritizedRunnable)1 PriorityBlockingQueue (java.util.concurrent.PriorityBlockingQueue)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1