本文整理汇总了Java中java.util.concurrent.ExecutorService.isShutdown方法的典型用法代码示例。如果您正苦于以下问题:Java ExecutorService.isShutdown方法的具体用法?Java ExecutorService.isShutdown怎么用?Java ExecutorService.isShutdown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.ExecutorService
的用法示例。
在下文中一共展示了ExecutorService.isShutdown方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shutdownAndAwaitTermination
import java.util.concurrent.ExecutorService; //导入方法依赖的package包/类
/**
* Shutdown cordova thread pool. This assumes we are in control of all tasks running
* in the thread pool.
* Additional info: http://developer.android.com/reference/java/util/concurrent/ExecutorService.html
* @param pool Cordova application's thread pool
*/
private void shutdownAndAwaitTermination(ExecutorService pool) {
Log.d(TAG,"Attempting to shutdown cordova threadpool");
if(!pool.isShutdown()){
try {
// Disable new tasks from being submitted
pool.shutdown();
// Wait a while for existing tasks to terminate
if (!pool.awaitTermination(5, TimeUnit.SECONDS)) {
pool.shutdownNow(); // Cancel currently executing tasks
// Wait a while for tasks to respond to being cancelled
if (!pool.awaitTermination(30, TimeUnit.SECONDS)) {
System.err.println("Cordova thread pool did not terminate.");
}
}
}
catch (InterruptedException ie) {
// Preserve interrupt status
Thread.currentThread().interrupt();
}
}
}
示例2: shutdown
import java.util.concurrent.ExecutorService; //导入方法依赖的package包/类
public void shutdown() {
ExecutorService executor = null;
synchronized (this) {
// swap
if (service != null) {
executor = service;
service = null;
}
}
if (executor != null) {
// shutdown
if (!executor.isShutdown()) {
executor.shutdown();
}
// recycle
executor = null;
}
}
示例3: shutdown
import java.util.concurrent.ExecutorService; //导入方法依赖的package包/类
public void shutdown() {
ExecutorService executor = null;
synchronized (this) {
// swap
if (service != null) {
executor = service;
service = null;
}
}
if (executor != null) {
// shutdown
if (!executor.isShutdown()) {
executor.shutdown();
}
// recycle
executor = null;
}
}
示例4: sendNotificationWave
import java.util.concurrent.ExecutorService; //导入方法依赖的package包/类
/**
* That method starts a set of threads, each thread sends a given number of
* notifications.
* The number of threads can be set via the attribute numOfNotificationSenders.
* The number of notification sent by each thread can be set via
* the attribute numOfNotificationSenderLoops.
* Depending on the parameter customNotification we send either custom
* notification(s) or MBeanServer registration and unregistration notification(s).
* When customNotification=true the total number of notification(s) sent is
* (numOfNotificationSenders * numOfNotificationSenderLoops). They are
* sequentially of type NOTIF_TYPE_0 then NOTIF_TYPE_1 and so on.
*
* When customNotification=false the total number of notification(s) sent is
* (numOfNotificationSenders * numOfNotificationSenderLoops) registration
* notification(s)
* +
* (numOfNotificationSenders * numOfNotificationSenderLoops) unregistration
* notification(s)
*
* @throws java.lang.Exception
*/
public void sendNotificationWave(boolean customNotification) throws
Exception {
// Build the set of notification sender.
Collection<Callable<Integer>> tasks =
new HashSet<Callable<Integer>>(numOfNotificationSenders);
for (int i = 1; i <= numOfNotificationSenders; i++) {
tasks.add(new NotifSender(numOfNotificationSenderLoops,
customNotification, i));
}
// Start all notification sender in parallel.
ExecutorService execServ = null;
try {
execServ = Executors.newFixedThreadPool(numOfNotificationSenders);
List<Future<Integer>> taskHandlers = execServ.invokeAll(tasks);
checkNotifSenderThreadStatus(taskHandlers);
} finally {
if (!execServ.isShutdown()) {
execServ.shutdown();
}
}
}
示例5: validateTestTree
import java.util.concurrent.ExecutorService; //导入方法依赖的package包/类
@Override
public boolean validateTestTree(final String sessionId) {
final TestTree copy = getTree(sessionId);
if (null == copy) {
throw new IllegalStateException("Test tree does not exist for session. Session ID: '" + sessionId + "'.");
}
synchronized (this) {
final ExecutorService executorService = getExecutorService(sessionId);
if (debugEnabled) {
LOGGER.debug("Validating test tree for session: '" + sessionId + "'.");
}
if (!executorService.isShutdown()) {
if (debugEnabled) {
LOGGER.debug("Test tree is incomplete. Waiting for executors to finish the tree state update...");
}
try {
executorService.shutdown();
executorService.awaitTermination(timeout, MILLISECONDS);
} catch (final InterruptedException e) {
throw new RuntimeException(e);
}
if (debugEnabled) {
LOGGER.debug("Test tree is in complete state.");
}
}
return validate(getTree(sessionId));
}
}
示例6: getExecutorService
import java.util.concurrent.ExecutorService; //导入方法依赖的package包/类
private ExecutorService getExecutorService() {
ExecutorService cexecutor = executor;
if (cexecutor == null || cexecutor.isShutdown()) {
cexecutor = SHARED_EXECUTOR;
}
return cexecutor;
}
示例7: received
import java.util.concurrent.ExecutorService; //导入方法依赖的package包/类
public void received(Channel channel, Object message) throws RemotingException {
ExecutorService cexecutor = executor;
if (cexecutor == null || cexecutor.isShutdown()) {
cexecutor = SHARED_EXECUTOR;
}
try {
cexecutor.execute(new ChannelEventRunnable(channel, handler, ChannelState.RECEIVED, message));
} catch (Throwable t) {
throw new ExecutionException(message, channel, getClass() + " error when process received event .", t);
}
}
示例8: caught
import java.util.concurrent.ExecutorService; //导入方法依赖的package包/类
public void caught(Channel channel, Throwable exception) throws RemotingException {
ExecutorService cexecutor = executor;
if (cexecutor == null || cexecutor.isShutdown()) {
cexecutor = SHARED_EXECUTOR;
}
try{
cexecutor.execute(new ChannelEventRunnable(channel, handler ,ChannelState.CAUGHT, exception));
}catch (Throwable t) {
throw new ExecutionException("caught event", channel, getClass()+" error when process caught event ." , t);
}
}