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


Java ThreadPoolExecutor类代码示例

本文整理汇总了Java中org.apache.tomcat.util.threads.ThreadPoolExecutor的典型用法代码示例。如果您正苦于以下问题:Java ThreadPoolExecutor类的具体用法?Java ThreadPoolExecutor怎么用?Java ThreadPoolExecutor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: shutdownExecutor

import org.apache.tomcat.util.threads.ThreadPoolExecutor; //导入依赖的package包/类
public void shutdownExecutor() {
    if ( executor!=null && internalExecutor ) {
        if ( executor instanceof ThreadPoolExecutor ) {
            //this is our internal one, so we need to shut it down
            ThreadPoolExecutor tpe = (ThreadPoolExecutor) executor;
            tpe.shutdownNow();
            long timeout = getExecutorTerminationTimeoutMillis();
            if (timeout > 0) {
                try {
                    tpe.awaitTermination(timeout, TimeUnit.MILLISECONDS);
                } catch (InterruptedException e) {
                    // Ignore
                }
                if (tpe.isTerminating()) {
                    getLog().warn(sm.getString("endpoint.warn.executorShutdown", getName()));
                }
            }
            TaskQueue queue = (TaskQueue) tpe.getQueue();
            queue.setParent(null);
        }
        executor = null;
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:24,代码来源:AbstractEndpoint.java

示例2: onApplicationEvent

import org.apache.tomcat.util.threads.ThreadPoolExecutor; //导入依赖的package包/类
@Override
public void onApplicationEvent(ContextClosedEvent event) {
    this.connector.pause();
    Executor executor = this.connector.getProtocolHandler().getExecutor();
    if (executor instanceof ThreadPoolExecutor) {
        try {
            ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executor;
            threadPoolExecutor.shutdown();
            if (!threadPoolExecutor.awaitTermination(30, TimeUnit.SECONDS)) {
                log.warn("Tomcat thread pool did not shut down gracefully within "
                        + "30 seconds. Proceeding with forceful shutdown");
            }
        }
        catch (InterruptedException ex) {
            Thread.currentThread().interrupt();
        }
    }
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:19,代码来源:App.java

示例3: onApplicationEvent

import org.apache.tomcat.util.threads.ThreadPoolExecutor; //导入依赖的package包/类
@Override
public void onApplicationEvent(ContextClosedEvent event) {
	log.info("Starting graceful shutdown of Tomcat");
	if (this.connector != null)
	{
		this.connector.pause();
        Executor executor = this.connector.getProtocolHandler().getExecutor();
        if (executor instanceof ThreadPoolExecutor) {
            try {
                ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executor;
                threadPoolExecutor.shutdown();
                if (!threadPoolExecutor.awaitTermination(20, TimeUnit.SECONDS)) {
                    log.warn("Tomcat thread pool did not shut down gracefully within "
                            + "20 seconds. Proceeding with forceful shutdown");
                }
                else
                {
                    log.info("Thread pool has closed");
                }
            }
            catch (InterruptedException ex) {
                Thread.currentThread().interrupt();
            }
        }
	}
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:27,代码来源:App.java

示例4: startInternal

import org.apache.tomcat.util.threads.ThreadPoolExecutor; //导入依赖的package包/类
/**
 * Start the component and implement the requirements of
 * {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
 *
 * @exception LifecycleException
 *                if this component detects a fatal error that prevents this
 *                component from being used
 */
@Override
protected void startInternal() throws LifecycleException {

	taskqueue = new TaskQueue(maxQueueSize);
	TaskThreadFactory tf = new TaskThreadFactory(namePrefix, daemon, getThreadPriority());
	executor = new ThreadPoolExecutor(getMinSpareThreads(), getMaxThreads(), maxIdleTime, TimeUnit.MILLISECONDS,
			taskqueue, tf);
	executor.setThreadRenewalDelay(threadRenewalDelay);
	if (prestartminSpareThreads) {
		executor.prestartAllCoreThreads();
	}
	taskqueue.setParent(executor);

	setState(LifecycleState.STARTING);
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:24,代码来源:StandardThreadExecutor.java

示例5: createAsynchronousChannelGroup

import org.apache.tomcat.util.threads.ThreadPoolExecutor; //导入依赖的package包/类
private static AsynchronousChannelGroup createAsynchronousChannelGroup() {
	// Need to do this with the right thread context class loader else the
	// first web app to call this will trigger a leak
	ClassLoader original = Thread.currentThread().getContextClassLoader();

	try {
		Thread.currentThread().setContextClassLoader(AsyncIOThreadFactory.class.getClassLoader());

		// These are the same settings as the default
		// AsynchronousChannelGroup
		int initialSize = Runtime.getRuntime().availableProcessors();
		ExecutorService executorService = new ThreadPoolExecutor(0, Integer.MAX_VALUE, Long.MAX_VALUE,
				TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>(), new AsyncIOThreadFactory());

		try {
			return AsynchronousChannelGroup.withCachedThreadPool(executorService, initialSize);
		} catch (IOException e) {
			// No good reason for this to happen.
			throw new IllegalStateException(sm.getString("asyncChannelGroup.createFail"));
		}
	} finally {
		Thread.currentThread().setContextClassLoader(original);
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:25,代码来源:AsyncChannelGroupUtil.java

示例6: shutdownExecutor

import org.apache.tomcat.util.threads.ThreadPoolExecutor; //导入依赖的package包/类
public void shutdownExecutor() {
	if (executor != null && internalExecutor) {
		if (executor instanceof ThreadPoolExecutor) {
			// this is our internal one, so we need to shut it down
			ThreadPoolExecutor tpe = (ThreadPoolExecutor) executor;
			tpe.shutdownNow();
			long timeout = getExecutorTerminationTimeoutMillis();
			if (timeout > 0) {
				try {
					tpe.awaitTermination(timeout, TimeUnit.MILLISECONDS);
				} catch (InterruptedException e) {
					// Ignore
				}
				if (tpe.isTerminating()) {
					getLog().warn(sm.getString("endpoint.warn.executorShutdown", getName()));
				}
			}
			TaskQueue queue = (TaskQueue) tpe.getQueue();
			queue.setParent(null);
		}
		executor = null;
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:24,代码来源:AbstractEndpoint.java

示例7: onApplicationEvent

import org.apache.tomcat.util.threads.ThreadPoolExecutor; //导入依赖的package包/类
@Override
public void onApplicationEvent(ContextClosedEvent event) {
    this.connector.pause();
    log.info("Shutting Down LivingDoc Remote Agent");
    Executor executor = this.connector.getProtocolHandler().getExecutor();
    if (executor instanceof ThreadPoolExecutor) {
        try {
            ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executor;
            threadPoolExecutor.shutdown();
            if (!threadPoolExecutor.awaitTermination(30, TimeUnit.SECONDS)) {
                log.warn("Tomcat thread pool did not shut down gracefully within "
                        + "30 seconds. Proceeding with forceful shutdown");
            }
        } catch (InterruptedException ex) {
            Thread.currentThread().interrupt();
        }
    }
}
 
开发者ID:testIT-LivingDoc,项目名称:livingdoc-core,代码行数:19,代码来源:ServerConfiguration.java

示例8: shutdownExecutor

import org.apache.tomcat.util.threads.ThreadPoolExecutor; //导入依赖的package包/类
public void shutdownExecutor() {
	if (executor != null && internalExecutor) {
		if (executor instanceof ThreadPoolExecutor) {
			// this is our internal one, so we need to shut it down
			ThreadPoolExecutor tpe = (ThreadPoolExecutor) executor;
			tpe.shutdownNow();
			long timeout = getExecutorTerminationTimeoutMillis();
			if (timeout > 0) {
				try {
					tpe.awaitTermination(timeout, TimeUnit.MILLISECONDS);
				} catch (InterruptedException e) {
					// Ignore
				}
				if (tpe.isTerminating()) {
					getLog().warn(
							sm.getString("endpoint.warn.executorShutdown",
									getName()));
				}
			}
			TaskQueue queue = (TaskQueue) tpe.getQueue();
			queue.setParent(null);
		}
		executor = null;
	}
}
 
开发者ID:EdwardLee03,项目名称:tomcat-sr,代码行数:26,代码来源:AbstractEndpoint.java

示例9: startInternal

import org.apache.tomcat.util.threads.ThreadPoolExecutor; //导入依赖的package包/类
/**
 * Start the component and implement the requirements
 * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected void startInternal() throws LifecycleException {

    taskqueue = new TaskQueue(maxQueueSize);
    TaskThreadFactory tf = new TaskThreadFactory(namePrefix,daemon,getThreadPriority());
    executor = new ThreadPoolExecutor(getMinSpareThreads(), getMaxThreads(), maxIdleTime, TimeUnit.MILLISECONDS,taskqueue, tf);
    executor.setThreadRenewalDelay(threadRenewalDelay);
    if (prestartminSpareThreads) {
        executor.prestartAllCoreThreads();
    }
    taskqueue.setParent(executor);

    setState(LifecycleState.STARTING);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:22,代码来源:StandardThreadExecutor.java

示例10: stopIdleThreads

import org.apache.tomcat.util.threads.ThreadPoolExecutor; //导入依赖的package包/类
/**
 * Updates each ThreadPoolExecutor with the current time, which is the time
 * when a context is being stopped.
 * 
 * @param context
 *            the context being stopped, used to discover all the Connectors
 *            of its parent Service.
 */
private void stopIdleThreads(Context context) {
    if (serverStopping) return;

    if (!(context instanceof StandardContext) ||
        !((StandardContext) context).getRenewThreadsWhenStoppingContext()) {
        log.debug("Not renewing threads when the context is stopping. "
            + "It is not configured to do it.");
        return;
    }

    Engine engine = (Engine) context.getParent().getParent();
    Service service = engine.getService();
    Connector[] connectors = service.findConnectors();
    if (connectors != null) {
        for (Connector connector : connectors) {
            ProtocolHandler handler = connector.getProtocolHandler();
            Executor executor = null;
            if (handler != null) {
                executor = handler.getExecutor();
            }

            if (executor instanceof ThreadPoolExecutor) {
                ThreadPoolExecutor threadPoolExecutor =
                    (ThreadPoolExecutor) executor;
                threadPoolExecutor.contextStopping();
            } else if (executor instanceof StandardThreadExecutor) {
                StandardThreadExecutor stdThreadExecutor =
                    (StandardThreadExecutor) executor;
                stdThreadExecutor.contextStopping();
            }

        }
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:43,代码来源:ThreadLocalLeakPreventionListener.java

示例11: createAsynchronousChannelGroup

import org.apache.tomcat.util.threads.ThreadPoolExecutor; //导入依赖的package包/类
private static AsynchronousChannelGroup createAsynchronousChannelGroup() {
    // Need to do this with the right thread context class loader else the
    // first web app to call this will trigger a leak
    ClassLoader original = Thread.currentThread().getContextClassLoader();

    try {
        Thread.currentThread().setContextClassLoader(
                AsyncIOThreadFactory.class.getClassLoader());

        // These are the same settings as the default
        // AsynchronousChannelGroup
        int initialSize = Runtime.getRuntime().availableProcessors();
        ExecutorService executorService = new ThreadPoolExecutor(
                0,
                Integer.MAX_VALUE,
                Long.MAX_VALUE, TimeUnit.MILLISECONDS,
                new SynchronousQueue<Runnable>(),
                new AsyncIOThreadFactory());

        try {
            return AsynchronousChannelGroup.withCachedThreadPool(
                    executorService, initialSize);
        } catch (IOException e) {
            // No good reason for this to happen.
            throw new IllegalStateException(sm.getString("asyncChannelGroup.createFail"));
        }
    } finally {
        Thread.currentThread().setContextClassLoader(original);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:31,代码来源:AsyncChannelGroupUtil.java

示例12: setMinSpareThreads

import org.apache.tomcat.util.threads.ThreadPoolExecutor; //导入依赖的package包/类
public void setMinSpareThreads(int minSpareThreads) {
    this.minSpareThreads = minSpareThreads;
    Executor executor = this.executor;
    if (internalExecutor && executor instanceof java.util.concurrent.ThreadPoolExecutor) {
        // The internal executor should always be an instance of
        // j.u.c.ThreadPoolExecutor but it may be null if the endpoint is
        // not running.
        // This check also avoids various threading issues.
        ((java.util.concurrent.ThreadPoolExecutor) executor).setCorePoolSize(minSpareThreads);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:12,代码来源:AbstractEndpoint.java

示例13: setMaxThreads

import org.apache.tomcat.util.threads.ThreadPoolExecutor; //导入依赖的package包/类
public void setMaxThreads(int maxThreads) {
    this.maxThreads = maxThreads;
    Executor executor = this.executor;
    if (internalExecutor && executor instanceof java.util.concurrent.ThreadPoolExecutor) {
        // The internal executor should always be an instance of
        // j.u.c.ThreadPoolExecutor but it may be null if the endpoint is
        // not running.
        // This check also avoids various threading issues.
        ((java.util.concurrent.ThreadPoolExecutor) executor).setMaximumPoolSize(maxThreads);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:12,代码来源:AbstractEndpoint.java

示例14: getCurrentThreadCount

import org.apache.tomcat.util.threads.ThreadPoolExecutor; //导入依赖的package包/类
/**
 * Return the amount of threads that are managed by the pool.
 *
 * @return the amount of threads that are managed by the pool
 */
public int getCurrentThreadCount() {
    if (executor!=null) {
        if (executor instanceof ThreadPoolExecutor) {
            return ((ThreadPoolExecutor)executor).getPoolSize();
        } else if (executor instanceof ResizableExecutor) {
            return ((ResizableExecutor)executor).getPoolSize();
        } else {
            return -1;
        }
    } else {
        return -2;
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:19,代码来源:AbstractEndpoint.java

示例15: getCurrentThreadsBusy

import org.apache.tomcat.util.threads.ThreadPoolExecutor; //导入依赖的package包/类
/**
 * Return the amount of threads that are in use
 *
 * @return the amount of threads that are in use
 */
public int getCurrentThreadsBusy() {
    if (executor!=null) {
        if (executor instanceof ThreadPoolExecutor) {
            return ((ThreadPoolExecutor)executor).getActiveCount();
        } else if (executor instanceof ResizableExecutor) {
            return ((ResizableExecutor)executor).getActiveCount();
        } else {
            return -1;
        }
    } else {
        return -2;
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:19,代码来源:AbstractEndpoint.java


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