public DebuggableThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory); allowCoreThreadTimeOut(true); // block task submissions until queue has room. // this is fighting TPE's design a bit because TPE rejects if queue.offer reports a full queue. // we'll just override this with a handler that retries until it gets in. ugly, but effective. // (there is an extensive analysis of the options here at // http://today.java.net/pub/a/today/2008/10/23/creating-a-notifying-blocking-thread-pool-executor.html) this.setRejectedExecutionHandler(blockingExecutionHandler); }
HintsWriteExecutor(HintsCatalog catalog) { this.catalog = catalog; writeBuffer = ByteBuffer.allocateDirect(WRITE_BUFFER_SIZE); executor = DebuggableThreadPoolExecutor.createWithFixedPoolSize("HintsWriteExecutor", 1); }
/** * Returns a ThreadPoolExecutor with a fixed number of threads. * When all threads are actively executing tasks, new tasks are queued. * If (most) threads are expected to be idle most of the time, prefer createWithMaxSize() instead. * @param threadPoolName the name of the threads created by this executor * @param size the fixed number of threads for this executor * @return the new DebuggableThreadPoolExecutor */ public static DebuggableThreadPoolExecutor createWithFixedPoolSize(String threadPoolName, int size) { return createWithMaximumPoolSize(threadPoolName, size, Integer.MAX_VALUE, TimeUnit.SECONDS); }
/** * Send @param t and any exception wrapped by @param r to the default uncaught exception handler, * or log them if none such is set up */ public static void logExceptionsAfterExecute(Runnable r, Throwable t) { Throwable hiddenThrowable = extractThrowable(r); if (hiddenThrowable != null) handleOrLog(hiddenThrowable); // ThreadPoolExecutor will re-throw exceptions thrown by its Task (which will be seen by // the default uncaught exception handler) so we only need to do anything if that handler // isn't set up yet. if (t != null && Thread.getDefaultUncaughtExceptionHandler() == null) handleOrLog(t); }
@Override protected void afterExecute(Runnable r, Throwable t) { super.afterExecute(r, t); maybeResetTraceSessionWrapper(r); logExceptionsAfterExecute(r, t); }
@Override public void afterExecute(Runnable r, Throwable t) { DebuggableThreadPoolExecutor.maybeResetTraceSessionWrapper(r); if (t == null) t = DebuggableThreadPoolExecutor.extractThrowable(r); if (t != null) { if (t instanceof CompactionInterruptedException) { logger.info(t.getMessage()); if (t.getSuppressed() != null && t.getSuppressed().length > 0) logger.warn("Interruption of compaction encountered exceptions:", t); else logger.debug("Full interruption stack trace:", t); } else { DebuggableThreadPoolExecutor.handleOrLog(t); } } } }
public void rejectedExecution(Runnable task, ThreadPoolExecutor executor) { ((DebuggableThreadPoolExecutor) executor).onInitialRejection(task); BlockingQueue<Runnable> queue = executor.getQueue(); while (true) { if (executor.isShutdown()) { ((DebuggableThreadPoolExecutor) executor).onFinalRejection(task); throw new RejectedExecutionException("ThreadPoolExecutor has shut down"); } try { if (queue.offer(task, 1000, TimeUnit.MILLISECONDS)) { ((DebuggableThreadPoolExecutor) executor).onFinalAccept(task); break; } } catch (InterruptedException e) { throw new AssertionError(e); } } } };
public void maybeExecuteImmediately(Runnable command) { execute(command); }
protected void init() { this.cacheRefreshExecutor = new DebuggableThreadPoolExecutor(name + "Refresh", Thread.NORM_PRIORITY); this.cache = initCache(null); try { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); mbs.registerMBean(this, getObjectName()); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public void afterExecute(Runnable r, Throwable t) { super.afterExecute(r,t); DebuggableThreadPoolExecutor.logExceptionsAfterExecute(r, t); }
public void run() { try { runnable.run(); } catch (Throwable t) { JVMStabilityInspector.inspectThrowable(t); DebuggableThreadPoolExecutor.handleOrLog(t); } } }
@Override public void afterExecute(Runnable r, Throwable t) { DebuggableThreadPoolExecutor.maybeResetTraceSessionWrapper(r); if (t == null) t = DebuggableThreadPoolExecutor.extractThrowable(r); if (t != null) { if (t instanceof CompactionInterruptedException) { logger.info(t.getMessage()); if (t.getSuppressed() != null && t.getSuppressed().length > 0) logger.warn("Interruption of compaction encountered exceptions:", t); else logger.trace("Full interruption stack trace:", t); } else { DebuggableThreadPoolExecutor.handleOrLog(t); } } // Snapshots cannot be deleted on Windows while segments of the root element are mapped in NTFS. Compactions // unmap those segments which could free up a snapshot for successful deletion. SnapshotDeletingTask.rescheduleFailedTasks(); }
public void rejectedExecution(Runnable task, ThreadPoolExecutor executor) { ((DebuggableThreadPoolExecutor) executor).onInitialRejection(task); BlockingQueue<Runnable> queue = executor.getQueue(); while (true) { if (executor.isShutdown()) { ((DebuggableThreadPoolExecutor) executor).onFinalRejection(task); throw new RejectedExecutionException("ThreadPoolExecutor has shut down"); } try { if (queue.offer(task, 1000, TimeUnit.MILLISECONDS)) { ((DebuggableThreadPoolExecutor) executor).onFinalAccept(task); break; } } catch (InterruptedException e) { throw new AssertionError(e); } } } };
@Override protected void afterExecute(Runnable r, Throwable t) { super.afterExecute(r, t); maybeResetTraceSessionWrapper(r); logExceptionsAfterExecute(r, t); }
/** * Send @param t and any exception wrapped by @param r to the default uncaught exception handler, * or log them if none such is set up */ public static void logExceptionsAfterExecute(Runnable r, Throwable t) { Throwable hiddenThrowable = extractThrowable(r); if (hiddenThrowable != null) handleOrLog(hiddenThrowable); // ThreadPoolExecutor will re-throw exceptions thrown by its Task (which will be seen by // the default uncaught exception handler) so we only need to do anything if that handler // isn't set up yet. if (t != null && Thread.getDefaultUncaughtExceptionHandler() == null) handleOrLog(t); }
public void maybeExecuteImmediately(Runnable command) { execute(command); }
protected void init() { this.cacheRefreshExecutor = new DebuggableThreadPoolExecutor(name + "Refresh", Thread.NORM_PRIORITY); this.cache = initCache(null); try { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); mbs.registerMBean(this, getObjectName()); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public void afterExecute(Runnable r, Throwable t) { super.afterExecute(r,t); DebuggableThreadPoolExecutor.logExceptionsAfterExecute(r, t); }
public void run() { try { runnable.run(); } catch (Throwable t) { JVMStabilityInspector.inspectThrowable(t); DebuggableThreadPoolExecutor.handleOrLog(t); } } }
@Override public void afterExecute(Runnable r, Throwable t) { DebuggableThreadPoolExecutor.maybeResetTraceSessionWrapper(r); if (t == null) t = DebuggableThreadPoolExecutor.extractThrowable(r); if (t != null) { if (t instanceof CompactionInterruptedException) { logger.info(t.getMessage()); if (t.getSuppressed() != null && t.getSuppressed().length > 0) logger.warn("Interruption of compaction encountered exceptions:", t); else logger.trace("Full interruption stack trace:", t); } else { DebuggableThreadPoolExecutor.handleOrLog(t); } } // Snapshots cannot be deleted on Windows while segments of the root element are mapped in NTFS. Compactions // unmap those segments which could free up a snapshot for successful deletion. SnapshotDeletingTask.rescheduleFailedTasks(); }