/** * Create a new instance. * * @param coreThreads the number of threads to create before enqueueing tasks * @param maxThreads the maximum number of threads to create * @param keepAliveTime the amount of time that an idle thread should remain active * @param keepAliveTimeUnit the unit of time for {@code keepAliveTime} * @param queue the queue to use for tasks * @param threadFactory the thread factory to use for new threads * @param blocking {@code true} if the executor should block when the queue is full and no threads are available, {@code false} to use the handoff executor * @param handoffExecutor the executor which is called when blocking is disabled and a task cannot be accepted, or {@code null} to reject the task */ public QueueExecutor(final int coreThreads, final int maxThreads, final long keepAliveTime, final TimeUnit keepAliveTimeUnit, final Queue<Runnable> queue, final ThreadFactory threadFactory, final boolean blocking, final Executor handoffExecutor) { this(coreThreads, maxThreads, keepAliveTime, keepAliveTimeUnit, queue, threadFactory, blocking, handoffExecutor, JBossExecutors.directExecutor()); }
/** * Create an executor that executes each task in a new thread. * * @param factory the thread factory to use * @return the executor * @deprecated Use {@link EnhancedQueueExecutor} instead. */ @Deprecated public static BlockingExecutor threadFactoryExecutor(final ThreadFactory factory) { return new ThreadFactoryExecutor(factory, Integer.MAX_VALUE, false, directExecutor()); }
/** * Defer interrupts for the duration of some task. Once the task is complete, any deferred interrupt will be * delivered to the thread, thus the thread interrupt status should be checked upon return. If the current thread * is not a {@code JBossThread}, the task is simply run as-is. * * @param task the task to run */ public static void executeWithInterruptDeferred(final Runnable task) { executeWithInterruptDeferred(JBossExecutors.directExecutor(), task); }
/** * Run a task, invoking the given notifier with the given attachment. * * @param task the task * @param notifier the notifier * @param attachment the attachment * @param <R> the task type * @param <A> the attachment type */ public static <R extends Runnable, A> void run(R task, TaskNotifier<? super R, ? super A> notifier, A attachment) { run(task, directExecutor(), notifier, attachment); }
/** * Create an executor that executes each task in a new thread. By default up to the given number of threads may run * concurrently, after which new tasks will be rejected. * * @param factory the thread factory to use * @param maxThreads the maximum number of allowed threads * @return the executor * @deprecated Use {@link EnhancedQueueExecutor} instead. */ @Deprecated public static BlockingExecutor threadFactoryExecutor(final ThreadFactory factory, final int maxThreads) { return new ThreadFactoryExecutor(factory, maxThreads, false, directExecutor()); }
public static ExecutorService directExecutorService() { return new DelegatingExecutorService(JBossExecutors.directExecutor()); }
/** * Create an executor that executes each task in a new thread. By default up to the given number of threads may run * concurrently, after which the caller will block or new tasks will be rejected, according to the setting of the * {@code blocking} parameter. * * @param factory the thread factory to use * @param maxThreads the maximum number of allowed threads * @param blocking {@code true} if the submitter should block when the maximum number of threads has been reached * @return the executor * @deprecated Use {@link EnhancedQueueExecutor} instead. */ @Deprecated public static BlockingExecutor threadFactoryExecutor(final ThreadFactory factory, final int maxThreads, final boolean blocking) { return new ThreadFactoryExecutor(factory, maxThreads, blocking, directExecutor()); }
public static ExecutorService directExecutorService() { return new DelegatingExecutorService(JBossExecutors.directExecutor()); }
/** * Create a thread factory which resets all thread-local storage and delegates to the given thread factory. * You must have the {@link RuntimePermission}{@code ("modifyThread")} permission to use this method. * * @param delegate the delegate thread factory * @return the resetting thread factory * @throws SecurityException if the caller does not have the {@link RuntimePermission}{@code ("modifyThread")} * permission */ public static ThreadFactory resettingThreadFactory(final ThreadFactory delegate) throws SecurityException { return wrappingThreadFactory(resettingExecutor(directExecutor()), delegate); }
public FutureServiceContainer() { super(JBossExecutors.directExecutor()); }
/** * Run a task, invoking the given notifier with the given attachment. * * @param task the task * @param notifier the notifier * @param attachment the attachment * @param <R> the task type * @param <A> the attachment type */ public static <R extends Runnable, A> void run(R task, TaskNotifier<? super R, ? super A> notifier, A attachment) { run(task, directExecutor(), notifier, attachment); }
/** * Defer interrupts for the duration of some task. Once the task is complete, any deferred interrupt will be * delivered to the thread, thus the thread interrupt status should be checked upon return. If the current thread * is not a {@code JBossThread}, the task is simply run as-is. * * @param task the task to run */ public static void executeWithInterruptDeferred(final Runnable task) { executeWithInterruptDeferred(JBossExecutors.directExecutor(), task); }
/** * Defer interrupts for the duration of some task. Once the task is complete, any deferred interrupt will be * delivered to the thread, thus the thread interrupt status should be checked upon return. If the current thread * is not a {@code JBossThread}, the task is simply run as-is. * * @param task the task to run */ public static void executeWithInterruptDeferred(final Runnable task) { executeWithInterruptDeferred(JBossExecutors.directExecutor(), task); }
/** * Create an executor that executes each task in a new thread. * * @param factory the thread factory to use * @return the executor * @deprecated Use {@link EnhancedQueueExecutor} instead. */ @Deprecated public static BlockingExecutor threadFactoryExecutor(final ThreadFactory factory) { return new ThreadFactoryExecutor(factory, Integer.MAX_VALUE, false, directExecutor()); }
/** * Create an executor that executes each task in a new thread. * * @param factory the thread factory to use * @return the executor * @deprecated Use {@link EnhancedQueueExecutor} instead. */ @Deprecated public static BlockingExecutor threadFactoryExecutor(final ThreadFactory factory) { return new ThreadFactoryExecutor(factory, Integer.MAX_VALUE, false, directExecutor()); }
/** * Run a task, invoking the given notifier with the given attachment. * * @param task the task * @param notifier the notifier * @param attachment the attachment * @param <R> the task type * @param <A> the attachment type */ public static <R extends Runnable, A> void run(R task, TaskNotifier<? super R, ? super A> notifier, A attachment) { run(task, directExecutor(), notifier, attachment); }
/** * Create an executor that executes each task in a new thread. By default up to the given number of threads may run * concurrently, after which new tasks will be rejected. * * @param factory the thread factory to use * @param maxThreads the maximum number of allowed threads * @return the executor * @deprecated Use {@link EnhancedQueueExecutor} instead. */ @Deprecated public static BlockingExecutor threadFactoryExecutor(final ThreadFactory factory, final int maxThreads) { return new ThreadFactoryExecutor(factory, maxThreads, false, directExecutor()); }
/** * Create a thread factory which resets all thread-local storage and delegates to the given thread factory. * You must have the {@link RuntimePermission}{@code ("modifyThread")} permission to use this method. * * @param delegate the delegate thread factory * @return the resetting thread factory * @throws SecurityException if the caller does not have the {@link RuntimePermission}{@code ("modifyThread")} * permission */ public static ThreadFactory resettingThreadFactory(final ThreadFactory delegate) throws SecurityException { return wrappingThreadFactory(resettingExecutor(directExecutor()), delegate); }
/** * Create a thread factory which resets all thread-local storage and delegates to the given thread factory. * You must have the {@link RuntimePermission}{@code ("modifyThread")} permission to use this method. * * @param delegate the delegate thread factory * @return the resetting thread factory * @throws SecurityException if the caller does not have the {@link RuntimePermission}{@code ("modifyThread")} * permission */ public static ThreadFactory resettingThreadFactory(final ThreadFactory delegate) throws SecurityException { return wrappingThreadFactory(resettingExecutor(directExecutor()), delegate); }
public synchronized void start(final StartContext context) throws StartException { final TimeSpec keepAliveSpec = keepAlive; long keepAlive = keepAliveSpec == null ? Long.MAX_VALUE : keepAliveSpec.getUnit().toMillis(keepAliveSpec.getDuration()); final QueuelessExecutor queuelessExecutor = new QueuelessExecutor(threadFactoryValue.getValue(), JBossExecutors.directExecutor(), handoffExecutorValue.getOptionalValue(), keepAlive); queuelessExecutor.setMaxThreads(maxThreads); queuelessExecutor.setBlocking(blocking); executor = new ManagedQueuelessExecutorService(queuelessExecutor); }