本文整理匯總了Java中java.util.concurrent.ThreadPoolExecutor.AbortPolicy方法的典型用法代碼示例。如果您正苦於以下問題:Java ThreadPoolExecutor.AbortPolicy方法的具體用法?Java ThreadPoolExecutor.AbortPolicy怎麽用?Java ThreadPoolExecutor.AbortPolicy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.concurrent.ThreadPoolExecutor
的用法示例。
在下文中一共展示了ThreadPoolExecutor.AbortPolicy方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getExecutor
import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
public XExecutor getExecutor() {
if (executor == null) {
synchronized (DownloadThreadPool.class) {
if (executor == null) {
executor = new XExecutor(corePoolSize,
MAX_POOL_SIZE,
KEEP_ALIVE_TIME,
UNIT,
new PriorityBlockingQueue<Runnable>()/*無限容量的緩衝隊列*/,
Executors.defaultThreadFactory()/*線程創建工廠*/,
new ThreadPoolExecutor.AbortPolicy()/*繼續超出上限的策略,阻止*/);
}
}
}
return executor;
}
示例2: CountDownLatchHelper
import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
public CountDownLatchHelper() {
executes = Lists.newCopyOnWriteArrayList();
data = Lists.newCopyOnWriteArrayList();
threadPool= new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), Runtime.getRuntime().availableProcessors(),
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy());
}
示例3: getExecutorService
import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
public ExecutorService getExecutorService() {
final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("search-thread-%d")
.setDaemon(true).build();
return new ThreadPoolExecutor(DEFAULT_THREAD_MAX, DEFAULT_THREAD_MAX,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(1024), threadFactory, new ThreadPoolExecutor.AbortPolicy());
}
示例4: getExecutor
import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
public XExecutor getExecutor() {
if (executor == null) {
synchronized (UploadThreadPool.class) {
if (executor == null) {
executor = new XExecutor(corePoolSize, MAX_IMUM_POOL_SIZE, KEEP_ALIVE_TIME, UNIT, //
new PriorityBlockingQueue<Runnable>(), //無限容量的緩衝隊列
Executors.defaultThreadFactory(), //線程創建工廠
new ThreadPoolExecutor.AbortPolicy()); //繼續超出上限的策略,阻止
}
}
}
return executor;
}
示例5: getExecutor
import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
public XExecutor getExecutor() {
if (executor == null) {
synchronized (DownloadThreadPool.class) {
if (executor == null) {
executor = new XExecutor(corePoolSize, MAX_POOL_SIZE, KEEP_ALIVE_TIME, UNIT, //
new PriorityBlockingQueue<Runnable>(), //無限容量的緩衝隊列
Executors.defaultThreadFactory(), //線程創建工廠
new ThreadPoolExecutor.AbortPolicy()); //繼續超出上限的策略,阻止
}
}
}
return executor;
}
示例6: createPool
import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
protected synchronized static void createPool() {
BlockingQueue<Runnable> workers = new LinkedBlockingQueue<>();
RejectedExecutionHandler handler = new ThreadPoolExecutor.AbortPolicy();
mDownloadPool = new DownloadPool(
corePoolSize,
maxPoolSize,
keepAliveTime,
TimeUnit.MILLISECONDS,
workers,
Executors.defaultThreadFactory(),
handler);
}
示例7: TreadPool
import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
private TreadPool(int corePoolSize, int maximumPoolSize, long keepAliveTime) {
exec = new ThreadPoolExecutor(
corePoolSize,// 核心線程數
maximumPoolSize,// 最大線程數
keepAliveTime,//閑置線程存活時間
TimeUnit.SECONDS, // 時間單位
new LinkedBlockingDeque<Runnable>(), // 線程隊列
Executors.defaultThreadFactory(), // 線程工廠
new ThreadPoolExecutor.AbortPolicy() // 隊列已滿,而且當前線程數已經超過最大線程數時的異常處理策略
);
scheduleExec = Executors.newScheduledThreadPool(corePoolSize);
}
示例8: initial
import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
public void initial() {
RejectedExecutionHandler handler = null;
if (discard) {
handler = new ThreadPoolExecutor.DiscardPolicy();
} else {
handler = new ThreadPoolExecutor.AbortPolicy();
}
executor = new ThreadPoolExecutor(poolSize, poolSize, 60 * 1000L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>(10 * 1000),
new NamedThreadFactory("communication-async"), handler);
}
示例9: init
import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
@PostConstruct
public void init() {
ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
.setNameFormat("demo-pool-%d").build();
//通用線程池
executorService = new ThreadPoolExecutor(corePoolSize, maximumPoolSize,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy());
}
示例10: buildSimpleExecutorService
import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
public static ExecutorService buildSimpleExecutorService() {
ThreadFactory namedThreadFactory = Executors.defaultThreadFactory();
return new ThreadPoolExecutor(1, 1,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy());
}
示例11: setRejectedExecutionHandler
import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
/**
* Set the RejectedExecutionHandler to use for the ExecutorService.
* Default is the ExecutorService's default abort policy.
* @see java.util.concurrent.ThreadPoolExecutor.AbortPolicy
*/
public void setRejectedExecutionHandler(RejectedExecutionHandler rejectedExecutionHandler) {
this.rejectedExecutionHandler =
(rejectedExecutionHandler != null ? rejectedExecutionHandler : new ThreadPoolExecutor.AbortPolicy());
}