當前位置: 首頁>>代碼示例>>Java>>正文


Java ThreadPoolExecutor.isShutdown方法代碼示例

本文整理匯總了Java中java.util.concurrent.ThreadPoolExecutor.isShutdown方法的典型用法代碼示例。如果您正苦於以下問題:Java ThreadPoolExecutor.isShutdown方法的具體用法?Java ThreadPoolExecutor.isShutdown怎麽用?Java ThreadPoolExecutor.isShutdown使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.concurrent.ThreadPoolExecutor的用法示例。


在下文中一共展示了ThreadPoolExecutor.isShutdown方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: rejectedExecution

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("tccTransaction Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }

    if (runnable instanceof RejectedRunnable) {
        ((RejectedRunnable) runnable).rejected();
    } else {
        if (!executor.isShutdown()) {
            BlockingQueue<Runnable> queue = executor.getQueue();
            int discardSize = queue.size() >> 1;
            for (int i = 0; i < discardSize; i++) {
                queue.poll();
            }

            try {
                queue.put(runnable);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
 
開發者ID:yu199195,項目名稱:happylifeplat-tcc,代碼行數:25,代碼來源:RejectedPolicy.java

示例2: rejectedExecution

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("txTransaction Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }

    if (runnable instanceof RejectedRunnable) {
        ((RejectedRunnable) runnable).rejected();
    } else {
        if (!executor.isShutdown()) {
            BlockingQueue<Runnable> queue = executor.getQueue();
            int discardSize = queue.size() >> 1;
            for (int i = 0; i < discardSize; i++) {
                queue.poll();
            }

            try {
                queue.put(runnable);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
 
開發者ID:yu199195,項目名稱:happylifeplat-transaction,代碼行數:25,代碼來源:RejectedPolicy.java

示例3: rejectedExecution

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
public void rejectedExecution(Runnable task, ThreadPoolExecutor executor)
{
    ((DebuggableThreadPoolExecutor) executor).onInitialRejection(task);
    BlockingQueue<Runnable> queue = executor.getQueue();
    while (true)
    {
        if (executor.isShutdown())
        {
            ((DebuggableThreadPoolExecutor) executor).onFinalRejection(task);
            throw new RejectedExecutionException("ThreadPoolExecutor has shut down");
        }
        try
        {
            if (queue.offer(task, 1000, TimeUnit.MILLISECONDS))
            {
                ((DebuggableThreadPoolExecutor) executor).onFinalAccept(task);
                break;
            }
        }
        catch (InterruptedException e)
        {
            throw new AssertionError(e);
        }
    }
}
 
開發者ID:Netflix,項目名稱:sstable-adaptor,代碼行數:26,代碼來源:DebuggableThreadPoolExecutor.java

示例4: parallelPixelFromGeo

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
/**
 * 
 * @param coords
 * @return
 * @throws InterruptedException
 * @throws ExecutionException
 */
public List<double[]> parallelPixelFromGeo(final Coordinate[] coords)
		throws InterruptedException, ExecutionException {
	int processors = Runtime.getRuntime().availableProcessors();
	ThreadPoolExecutor executor = new ThreadPoolExecutor(2, processors, 2, TimeUnit.SECONDS,
			new LinkedBlockingQueue<Runnable>());//(ThreadPoolExecutor)Executors.newFixedThreadPool(processors);
	try {
		final List<Future<double[]>> tasks = new ArrayList<Future<double[]>>();
		for (int i = 0; i < coords.length; i++) {
			tasks.add(executor.submit(new ParallelReverse(coords[i].x, coords[i].y)));
		}
		executor.shutdown();

		final List<double[]> points = new ArrayList<double[]>();
		for (Future<double[]> result : tasks) {
			List<double[]> l = Arrays.asList(result.get());
			points.addAll(l);
		}

		return points;
	} catch (Exception e) {
		if (!executor.isShutdown())
			executor.shutdown();
		throw e;
	}
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:33,代碼來源:ParallelGeoCoding.java

示例5: rejectedExecution

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
    if (r instanceof AbstractRunnable) {
        if (((AbstractRunnable) r).isForceExecution()) {
            BlockingQueue<Runnable> queue = executor.getQueue();
            if (!(queue instanceof SizeBlockingQueue)) {
                throw new IllegalStateException("forced execution, but expected a size queue");
            }
            try {
                ((SizeBlockingQueue) queue).forcePut(r);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                throw new IllegalStateException("forced execution, but got interrupted", e);
            }
            return;
        }
    }
    rejected.inc();
    throw new EsRejectedExecutionException("rejected execution of " + r + " on " + executor, executor.isShutdown());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:21,代碼來源:EsAbortPolicy.java

示例6: interruptedTask

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
/**
 * 給線程池中所有的線程發出interrupted信號結束當前agent的壓測任務,但線程並不會立即停止
 * 
 * @author gaoxianglong
 */
public void interruptedTask() {
	ThreadPoolExecutor threadPool = threadPoolManager.getThreadPool();
	/* 隻有線程池未shutdown才允許shutdown */
	if (!threadPool.isShutdown()) {
		log.info("收到interrupted指令");
		while (true) {
			try {
				TimeUnit.SECONDS.sleep(1);
				if (0 < concurrentUsersSize) {
					/*
					 * 如果當前實際並發用戶等於concurrentUsersSize才允許對ThreadPool執行shutdownNow操作
					 * ,因為需要等待所有線程countDown,否則主線程就會一直阻塞
					 */
					if (concurrentUser.get() == concurrentUsersSize) {
						threadPoolManager.getThreadPool().shutdownNow();
						log.info("正在嘗試中斷當前agent的所有壓測任務...");
						break;
					}
				}
			} catch (InterruptedException e) {
				log.error("error", e);
			}
		}
	}
}
 
開發者ID:yunjiweidian,項目名稱:TITAN,代碼行數:31,代碼來源:RequestHandler.java

示例7: rejectedExecution

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("MythTransaction Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }

    if (runnable instanceof RejectedRunnable) {
        ((RejectedRunnable) runnable).rejected();
    } else {
        if (!executor.isShutdown()) {
            BlockingQueue<Runnable> queue = executor.getQueue();
            int discardSize = queue.size() >> 1;
            for (int i = 0; i < discardSize; i++) {
                queue.poll();
            }

            try {
                queue.put(runnable);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
 
開發者ID:yu199195,項目名稱:myth,代碼行數:25,代碼來源:RejectedPolicy.java

示例8: rejectedExecution

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
/**
 * Executes task r in the caller's thread, unless the executor
 * has been shut down, in which case the task is discarded.
 *
 * @param r the runnable task requested to be executed
 * @param e the executor attempting to execute this task
 */
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
    if (!e.isShutdown()) {
        // Wait for up to 1 second while the queue drains...
        boolean notified = false;
        try {
            notified = underLoad.await(false, 1, TimeUnit.SECONDS);
        } catch (InterruptedException exception) {
            log.debug("Got exception waiting for notification:", exception);
        } finally {
            if (!notified) {
                log.info("Waited for 1 second on {}. Proceeding with work...",
                         Thread.currentThread().getName());
            } else {
                log.info("FIXME we got a notice");
            }
        }
        // Do the work on the submitter's thread
        r.run();
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:28,代碼來源:BoundedThreadPool.java

示例9: rejectedExecution

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("txTransaction Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }

    if (!executor.isShutdown()) {
        try {
            executor.getQueue().put(runnable);
        } catch (InterruptedException e) {
        }
    }
}
 
開發者ID:yu199195,項目名稱:happylifeplat-transaction,代碼行數:14,代碼來源:BlockingPolicy.java

示例10: rejectedExecution

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("txTransaction Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }

    if (!executor.isShutdown()) {
        BlockingQueue<Runnable> queue = executor.getQueue();
        int discardSize = queue.size() >> 1;
        for (int i = 0; i < discardSize; i++) {
            queue.poll();
        }
        queue.offer(runnable);
    }
}
 
開發者ID:yu199195,項目名稱:happylifeplat-transaction,代碼行數:16,代碼來源:DiscardedPolicy.java

示例11: rejectedExecution

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
public void rejectedExecution(Runnable task, ThreadPoolExecutor executor)
{
    if (executor.isShutdown())
    {
        //Give some notification to the caller the task isn't going to run
        if (task instanceof Future)
            ((Future) task).cancel(false);

        logger.debug("ScheduledThreadPoolExecutor has shut down as part of C* shutdown");
    }
    else
    {
        throw new AssertionError("Unknown rejection of ScheduledThreadPoolExecutor task");
    }
}
 
開發者ID:Netflix,項目名稱:sstable-adaptor,代碼行數:16,代碼來源:DebuggableScheduledThreadPoolExecutor.java

示例12: rejectedExecution

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
@Override
public void rejectedExecution(final Runnable runnable, final ThreadPoolExecutor executor) {
    if (executor.isShutdown()) {
        return;
    }

    final Runnable lastTask = getLastElement(executor.getQueue());
    if (lastTask == null) {
        throw new IllegalStateException("ThreadPoolExecutor should not be full while queue is empty.");
    }
    executor.remove(lastTask);
    executor.submit(runnable);
}
 
開發者ID:ProgrammingLife2017,項目名稱:hygene,代碼行數:14,代碼來源:DiscardNewestPolicy.java

示例13: rejectedExecution

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("tccTransaction Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }

    if (!executor.isShutdown()) {
        try {
            executor.getQueue().put(runnable);
        } catch (InterruptedException e) {
        }
    }
}
 
開發者ID:yu199195,項目名稱:happylifeplat-tcc,代碼行數:14,代碼來源:BlockingPolicy.java

示例14: rejectedExecution

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("tccTransaction Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }
    if (!executor.isShutdown()) {
        BlockingQueue<Runnable> queue = executor.getQueue();
        int discardSize = queue.size() >> 1;
        for (int i = 0; i < discardSize; i++) {
            queue.poll();
        }
        queue.offer(runnable);
    }
}
 
開發者ID:yu199195,項目名稱:happylifeplat-tcc,代碼行數:15,代碼來源:DiscardedPolicy.java

示例15: rejectedExecution

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("MythTransaction Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }

    if (!executor.isShutdown()) {
        try {
            executor.getQueue().put(runnable);
        } catch (InterruptedException e) {
        }
    }
}
 
開發者ID:yu199195,項目名稱:myth,代碼行數:14,代碼來源:BlockingPolicy.java


注:本文中的java.util.concurrent.ThreadPoolExecutor.isShutdown方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。