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


Java ThreadPoolExecutor.setRejectedExecutionHandler方法代码示例

本文整理汇总了Java中java.util.concurrent.ThreadPoolExecutor.setRejectedExecutionHandler方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadPoolExecutor.setRejectedExecutionHandler方法的具体用法?Java ThreadPoolExecutor.setRejectedExecutionHandler怎么用?Java ThreadPoolExecutor.setRejectedExecutionHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.ThreadPoolExecutor的用法示例。


在下文中一共展示了ThreadPoolExecutor.setRejectedExecutionHandler方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
    ThreadPoolExecutor executor = new ThreadPoolExecutor(2, 2, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(2));

    executor.setRejectedExecutionHandler((task, exec) -> System.out.println(task.toString() + " : Rejected"));

    // Add some tasks
    for (int i = 0; i < 9; i++) {
        executor.execute(new WorkerTask("Task " + (i + 1)));
        // Sleep
        try {
            Thread.sleep(500);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
    }
    executor.shutdown();
    executor.awaitTermination(20, TimeUnit.SECONDS);
}
 
开发者ID:yohlulz,项目名称:MLE5109-Course-samples,代码行数:19,代码来源:Rejection.java

示例2: ReadaheadPool

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
private ReadaheadPool() {
  pool = new ThreadPoolExecutor(POOL_SIZE, MAX_POOL_SIZE, 3L, TimeUnit.SECONDS,
      new ArrayBlockingQueue<Runnable>(CAPACITY));
  pool.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardOldestPolicy());
  pool.setThreadFactory(new ThreadFactoryBuilder()
    .setDaemon(true)
    .setNameFormat("Readahead Thread #%d")
    .build());
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:10,代码来源:ReadaheadPool.java

示例3: Server

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * Constructor of the class. Creates the executor object
 */
public Server(){
	// Create the executor
	executor=(ThreadPoolExecutor)Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
	// Create the controller for the Rejected tasks
	RejectedTaskController controller=new RejectedTaskController();
	// Establish the rejected task controller
	executor.setRejectedExecutionHandler(controller);
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Concurrency-Cookbook-Second-Edition,代码行数:12,代码来源:Server.java

示例4: testSetRejectedExecutionHandler

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * setRejectedExecutionHandler sets the handler returned by
 * getRejectedExecutionHandler
 */
public void testSetRejectedExecutionHandler() {
    final ThreadPoolExecutor p =
        new ThreadPoolExecutor(1, 2,
                               LONG_DELAY_MS, MILLISECONDS,
                               new ArrayBlockingQueue<Runnable>(10));
    try (PoolCleaner cleaner = cleaner(p)) {
        RejectedExecutionHandler handler = new NoOpREHandler();
        p.setRejectedExecutionHandler(handler);
        assertSame(handler, p.getRejectedExecutionHandler());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:ThreadPoolExecutorTest.java

示例5: testSetRejectedExecutionHandlerNull

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * setRejectedExecutionHandler(null) throws NPE
 */
public void testSetRejectedExecutionHandlerNull() {
    final ThreadPoolExecutor p =
        new ThreadPoolExecutor(1, 2,
                               LONG_DELAY_MS, MILLISECONDS,
                               new ArrayBlockingQueue<Runnable>(10));
    try (PoolCleaner cleaner = cleaner(p)) {
        try {
            p.setRejectedExecutionHandler(null);
            shouldThrow();
        } catch (NullPointerException success) {}
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:ThreadPoolExecutorTest.java

示例6: testSetRejectedExecutionHandler

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * setRejectedExecutionHandler sets the handler returned by
 * getRejectedExecutionHandler
 */
public void testSetRejectedExecutionHandler() {
    final ThreadPoolExecutor p =
        new CustomTPE(1, 2,
                      LONG_DELAY_MS, MILLISECONDS,
                      new ArrayBlockingQueue<Runnable>(10));
    try (PoolCleaner cleaner = cleaner(p)) {
        RejectedExecutionHandler handler = new NoOpREHandler();
        p.setRejectedExecutionHandler(handler);
        assertSame(handler, p.getRejectedExecutionHandler());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:ThreadPoolExecutorSubclassTest.java

示例7: testSetRejectedExecutionHandlerNull

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * setRejectedExecutionHandler(null) throws NPE
 */
public void testSetRejectedExecutionHandlerNull() {
    final ThreadPoolExecutor p =
        new CustomTPE(1, 2,
                      LONG_DELAY_MS, MILLISECONDS,
                      new ArrayBlockingQueue<Runnable>(10));
    try (PoolCleaner cleaner = cleaner(p)) {
        try {
            p.setRejectedExecutionHandler(null);
            shouldThrow();
        } catch (NullPointerException success) {}
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:ThreadPoolExecutorSubclassTest.java

示例8: setRejectedExecutionHandler

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
void setRejectedExecutionHandler(
    ThreadPoolExecutor p, RejectedExecutionHandler handler) {
    p.setRejectedExecutionHandler(handler);
    assertSame(handler, p.getRejectedExecutionHandler());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:JSR166TestCase.java


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