public void execute(final Runnable command) { final JBossThread thr = JBossThread.currentThread(); final String oldName = thr.getName(); thr.setName(thr.getThreadNameInfo().format(thr, nameFormat)); try { delegate.execute(command); } finally { thr.setName(oldName); } }
private void runTask(Runnable task) { if (task != null) try { taskExecutor.execute(task); } catch (Throwable t) { Messages.msg.executionFailed(t, 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); }
public static ExecutorService directExecutorService() { return new DelegatingExecutorService(JBossExecutors.directExecutor()); }
public void execute(final DirectExecutor directExecutor, final Runnable task) throws RejectedExecutionException { execute(JBossExecutors.executorTask(directExecutor, task)); } }
/** * Create a direct executor which delegates tasks to the given executor, and then clears <b>all</b> thread-local * data after each task completes (regardless of outcome). You must have the {@link RuntimePermission}{@code ("modifyThread")} * permission to use this method. * * @param delegate the delegate direct executor * @return a resetting executor * @throws SecurityException if the caller does not have the {@link RuntimePermission}{@code ("modifyThread")} permission */ public static DirectExecutor resettingExecutor(final DirectExecutor delegate) throws SecurityException { return cleanupExecutor(delegate, threadLocalResetter()); }
public void run() { JBossExecutors.run(getDelegate(), notifier, attachment); } }
public void execute(final Runnable command) { JBossExecutors.run(command, getDelegate(), notifier, attachment); } }
/** * Construct a new instance using a bounded FIFO queue of the given size and a blocking reject policy. * * @param parent the parent to delegate tasks to * @param queueLength the fixed length of the queue to use to hold tasks */ public OrderedExecutor(final Executor parent, final int queueLength) { this(parent, new ArrayQueue<Runnable>(queueLength), true, null); }
/** * Determine whether shutdown was requested on this thread pool. * * @return {@code true} if shutdown was requested, {@code false} otherwise */ public boolean isShutdown() { return isShutdownRequested(threadStatus); }
/** * Get the maximum queue size. If the queue is full and a task cannot be immediately accepted, rejection will result. * * @return the maximum queue size * @see Builder#getMaximumQueueSize() Builder.getMaximumQueueSize() */ public int getMaximumQueueSize() { return maxQueueSizeOf(queueSize); }
/** * Get an estimate of the current queue size. * * @return an estimate of the current queue size */ public int getQueueSize() { return currentQueueSizeOf(queueSize); }
/** * Get an estimate of the current number of active threads in the pool. * * @return an estimate of the current number of active threads in the pool */ public int getPoolSize() { return currentSizeOf(threadStatus); }
/** * Create a wrapping executor for a delegate executor which creates an {@link #executorTask(DirectExecutor, Runnable)} for * each task. * * @param delegate the delegate executor * @return the wrapping executor */ public static WrappingExecutor wrappingExecutor(final Executor delegate) { return new DelegatingWrappingExecutor(delegate); }
/** * Get a task that runs the given task through the given direct executor. * * @param executor the executor to run the task through * @param task the task to run * @return an encapsulating task */ public static Runnable executorTask(final DirectExecutor executor, final Runnable task) { return new ExecutorTask(executor, task); }
/** * Get an uncaught exception handler which logs to the given logger. * * @param log the logger * @return the handler */ public static Thread.UncaughtExceptionHandler loggingExceptionHandler(final Logger log) { return new LoggingUncaughtExceptionHandler(log); }
void run() { try { listener.handleEvent(attachment); } catch (Throwable t) { // todo log it } } }