本文整理汇总了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));
}
}