@Override public ScheduledExecutorService newScheduledThreadPool(ThreadPoolProfile profile, ThreadFactory threadFactory) { RejectedExecutionHandler rejectedExecutionHandler = profile.getRejectedExecutionHandler(); if (rejectedExecutionHandler == null) { rejectedExecutionHandler = new ThreadPoolExecutor.CallerRunsPolicy(); } ScheduledThreadPoolExecutor answer = new RejectableScheduledThreadPoolExecutor( profile.getPoolSize(), threadFactory, rejectedExecutionHandler) { protected void beforeExecute(Thread t, Runnable r) { super.beforeExecute(t, r); before(); } protected void afterExecute(Runnable r, Throwable t) { super.afterExecute(r, t); after(); } }; // need to wrap the thread pool in a sized to guard against the problem that the // JDK created thread pool has an unbounded queue (see class javadoc), which mean // we could potentially keep adding tasks, and run out of memory. if (profile.getMaxPoolSize() > 0) { return new SizedScheduledExecutorService(answer, profile.getMaxQueueSize()); } else { return answer; } }
@Override public ScheduledExecutorService newScheduledThreadPool(ThreadPoolProfile profile, ThreadFactory threadFactory) { RejectedExecutionHandler rejectedExecutionHandler = profile.getRejectedExecutionHandler(); if (rejectedExecutionHandler == null) { rejectedExecutionHandler = new ThreadPoolExecutor.CallerRunsPolicy(); } ScheduledThreadPoolExecutor answer = new RejectableScheduledThreadPoolExecutor( profile.getPoolSize(), threadFactory, rejectedExecutionHandler) { protected void beforeExecute(Thread t, Runnable r) { super.beforeExecute(t, r); before(); } protected void afterExecute(Runnable r, Throwable t) { super.afterExecute(r, t); after(); } }; // need to wrap the thread pool in a sized to guard against the problem that the // JDK created thread pool has an unbounded queue (see class javadoc), which mean // we could potentially keep adding tasks, and run out of memory. if (profile.getMaxPoolSize() > 0) { return new SizedScheduledExecutorService(answer, profile.getMaxQueueSize()); } else { return answer; } }
@Override public ExecutorService newThreadPool(ThreadPoolProfile profile, ThreadFactory factory) { return newThreadPool(profile.getPoolSize(), profile.getMaxPoolSize(), profile.getKeepAliveTime(), profile.getTimeUnit(), profile.getMaxQueueSize(), profile.getRejectedExecutionHandler(), factory); }
@Override public ExecutorService newThreadPool(ThreadPoolProfile profile, ThreadFactory factory) { return newThreadPool(profile.getPoolSize(), profile.getMaxPoolSize(), profile.getKeepAliveTime(), profile.getTimeUnit(), profile.getMaxQueueSize(), profile.getRejectedExecutionHandler(), factory); }