当前位置: 首页>>代码示例>>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;未经允许,请勿转载。