當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。