本文整理匯總了Java中java.util.concurrent.ThreadPoolExecutor.DiscardPolicy方法的典型用法代碼示例。如果您正苦於以下問題:Java ThreadPoolExecutor.DiscardPolicy方法的具體用法?Java ThreadPoolExecutor.DiscardPolicy怎麽用?Java ThreadPoolExecutor.DiscardPolicy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.concurrent.ThreadPoolExecutor
的用法示例。
在下文中一共展示了ThreadPoolExecutor.DiscardPolicy方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createDefaultThreadPool
import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
public static ThreadPoolExecutor createDefaultThreadPool() {
// 控製最多4個keep在pool中
int corePoolSize = Math.min(4, CPU_CORE);
return new ThreadPoolExecutor(
corePoolSize,
Integer.MAX_VALUE,
DEFAULT_CACHE_SENCOND, TimeUnit.SECONDS,
new SynchronousQueue<Runnable>(),
new ThreadFactory() {
static final String NAME = "lite-";
AtomicInteger IDS = new AtomicInteger(1);
@Override
public Thread newThread(Runnable r) {
return new Thread(r, NAME + IDS.getAndIncrement());
}
},
new ThreadPoolExecutor.DiscardPolicy());
}
示例2: createIOPoolExecutor
import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
private ThreadPoolExecutor createIOPoolExecutor(){
//IO線程工廠類
ThreadFactory threadFactory = new ThreadFactory() {
@Override
public Thread newThread(@NonNull Runnable runnable) {
Thread thread = new Thread(runnable);
thread.setName("dunit-io");
return thread;
}
};
//創建一個任務拒絕策略
//直接忽略新進的任務
RejectedExecutionHandler rejectedExecutionHandler = new ThreadPoolExecutor.DiscardPolicy();
//創建一個最大線程數為3的線程池
ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(1, 3, 3, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(10),threadFactory,rejectedExecutionHandler);
//當核心線程空閑時,允許殺死核心線程
poolExecutor.allowCoreThreadTimeOut(true);
return poolExecutor;
}
示例3: LifecycleModule
import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
public LifecycleModule() {
// The thread pool is unbounded, so use direct handoff
BlockingQueue<Runnable> queue = new SynchronousQueue<Runnable>();
// Discard tasks that are submitted during shutdown
RejectedExecutionHandler policy =
new ThreadPoolExecutor.DiscardPolicy();
// Create threads as required and keep them in the pool for 60 seconds
ioExecutor = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
60, SECONDS, queue, policy);
}
示例4: CryptoModule
import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
public CryptoModule() {
// Use an unbounded queue
BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>();
// Discard tasks that are submitted during shutdown
RejectedExecutionHandler policy =
new ThreadPoolExecutor.DiscardPolicy();
// Create a limited # of threads and keep them in the pool for 60 secs
cryptoExecutor = new TimeLoggingExecutor("CryptoExecutor", 0,
MAX_EXECUTOR_THREADS, 60, SECONDS, queue, policy);
}
示例5: DatabaseExecutorModule
import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
public DatabaseExecutorModule() {
// Use an unbounded queue
BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>();
// Discard tasks that are submitted during shutdown
RejectedExecutionHandler policy =
new ThreadPoolExecutor.DiscardPolicy();
// Use a single thread and keep it in the pool for 60 secs
databaseExecutor = new TimeLoggingExecutor("DatabaseExecutor", 0, 1,
60, SECONDS, queue, policy);
}
示例6: getInstance
import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
public static RealTimeThreadPool getInstance() {
if (null == mInstance) {
synchronized (lock) {
if (null == mInstance) {
mInstance = new RealTimeThreadPool();
executorService = new ThreadPoolExecutor(1, 10, 120, TimeUnit.SECONDS, new
SynchronousQueue<Runnable>(),
new DefaultThreadFactory(), new ThreadPoolExecutor.DiscardPolicy());
}
}
}
return mInstance;
}
示例7: 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);
}
示例8: createExecutor
import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
private ExecutorService createExecutor(Config config) {
ThreadPoolExecutor service = new ThreadPoolExecutor(config.core, config.max, config.timeout,
TimeUnit.MILLISECONDS, new PriorityBlockingQueue<Runnable>(QUEUE_INIT_CAPACITY, mQueueComparator),
new TaskThreadFactory(name), new ThreadPoolExecutor.DiscardPolicy());
allowCoreThreadTimeOut(service, config.allowCoreTimeOut);
return service;
}
示例9: createExecutor
import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
private ExecutorService createExecutor(Config config) {
ThreadPoolExecutor service = new ThreadPoolExecutor(config.core, config.max, config.timeout,
TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(QUEUE_INIT_CAPACITY),
new TaskThreadFactory(name), new ThreadPoolExecutor.DiscardPolicy());
allowCoreThreadTimeOut(service, config.allowCoreTimeOut);
return service;
}
示例10: GenericConnectionManager
import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
public GenericConnectionManager(
TransactionManager transactionManager,
TransactionSupportLevel transactionSupportLevel,
SubjectSource subjectSource,
ClassLoader classLoader,
ManagedConnectionFactory managedConnectionFactory,
String name,
String poolName,
int minIdle,
int maxPoolSize,
long connectionTimeout,
long idleTimeout,
long maxLifetime,
long aliveBypassWindow,
long houseKeepingPeriod) {
this.transactionManager = transactionManager;
this.transactionSupportLevel = transactionSupportLevel;
this.subjectSource = subjectSource;
this.classLoader = classLoader;
this.managedConnectionFactory = managedConnectionFactory;
this.name = name;
this.poolName = poolName;
this.minIdle = minIdle;
this.maxPoolSize = maxPoolSize;
this.connectionTimeout = connectionTimeout;
this.idleTimeout = idleTimeout;
this.maxLifetime = maxLifetime;
this.aliveBypassWindow = aliveBypassWindow;
this.houseKeepingPeriod = houseKeepingPeriod;
final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1, new UtilityElf.DefaultThreadFactory(poolName + " housekeeper", true), new ThreadPoolExecutor.DiscardPolicy());
executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
executor.setRemoveOnCancelPolicy(true);
this.houseKeepingExecutorService = executor;
this.addConnectionExecutor = createThreadPoolExecutor(this.maxPoolSize, poolName + " connection adder", null, new ThreadPoolExecutor.DiscardPolicy());
this.closeConnectionExecutor = createThreadPoolExecutor(this.maxPoolSize, poolName + " connection closer", null, new ThreadPoolExecutor.CallerRunsPolicy());
this.houseKeeperTask = this.houseKeepingExecutorService.scheduleWithFixedDelay(this::houseKeep, 100L, this.houseKeepingPeriod, MILLISECONDS);
if (transactionManager != null && name != null) {
transactionManager.registerResource(new RecoverableResourceFactoryImpl(managedConnectionFactory, name));
}
}