当前位置: 首页>>代码示例>>Java>>正文


Java ThreadPoolExecutor.DiscardPolicy方法代码示例

本文整理汇总了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());
}
 
开发者ID:BaoBaoJianqiang,项目名称:CustomListView,代码行数:20,代码来源:SmartExecutor.java

示例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;
}
 
开发者ID:tik5213,项目名称:DUnit,代码行数:21,代码来源:DUnitThreadManager.java

示例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);
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:11,代码来源:LifecycleModule.java

示例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);
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:11,代码来源:CryptoModule.java

示例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);
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:11,代码来源:DatabaseExecutorModule.java

示例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;
}
 
开发者ID:jonyChina162,项目名称:okhttpNDS,代码行数:14,代码来源:RealTimeThreadPool.java

示例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);
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:13,代码来源:DefaultCommunicationClientImpl.java

示例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;
}
 
开发者ID:newDeepLearing,项目名称:decoy,代码行数:10,代码来源:TaskExecutor.java

示例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;
}
 
开发者ID:newDeepLearing,项目名称:decoy,代码行数:10,代码来源:NimTaskExecutor.java

示例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));
    }
}
 
开发者ID:ops4j,项目名称:org.ops4j.pax.transx,代码行数:46,代码来源:GenericConnectionManager.java


注:本文中的java.util.concurrent.ThreadPoolExecutor.DiscardPolicy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。