专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > 高性能WEB开发

java的Executor类的性能,该怎么处理

发布时间:2010-05-20 14:01:29 文章来源:www.iduyao.cn 采编人员:星星草
java的Executor类的性能
近来开发一个机遇java的C/S架构的项目,需要考虑到并发量的问题,不知道Executor类的性能如何,能经得起多少的并发量呢?手写的线程池(足够好的话)会比它强吗
------解决方案--------------------
这个受你的服务器配置及应用场景影响了
发你段手工写的代码,你可以动态改变线程池的大小,保持连接的时间等参数,有点定制化的意思


public class ThreadPoolTaskExecutor extends CustomizableThreadFactory implements ExecutorService, SchedulingTaskExecutor, Executor, BeanNameAware, InitializingBean, DisposableBean {

    protected final Logger           logger                           = LoggerFactory.getLogger(getClass());

    private final Object             poolSizeMonitor                  = new Object();

    private int                      corePoolSize                     = 1;

    private int                      maxPoolSize                      = Integer.MAX_VALUE;

    private int                      keepAliveSeconds                 = 60;

    private boolean                  allowCoreThreadTimeOut           = false;

    private int                      queueCapacity                    = Integer.MAX_VALUE;

    private ThreadFactory            threadFactory                    = this;

    // 替换为调用方执行的handler
    private RejectedExecutionHandler rejectedExecutionHandler         = new ThreadPoolExecutor.CallerRunsPolicy();

    private boolean                  waitForTasksToCompleteOnShutdown = false;

    private boolean                  threadNamePrefixSet              = false;

    private String                   beanName;

    private ThreadPoolExecutor       threadPoolExecutor;

    /**
     * Set the ThreadPoolExecutor's core pool size. Default is 1.
     * <p>
     * <b>This setting can be modified at runtime, for example through JMX.</b>
     */
    public void setCorePoolSize(int corePoolSize) {
        synchronized (this.poolSizeMonitor) {
            this.corePoolSize = corePoolSize;
            if (this.threadPoolExecutor != null) {
                this.threadPoolExecutor.setCorePoolSize(corePoolSize);
            }
        }
    }

    /**
     * Return the ThreadPoolExecutor's core pool size.
     */
    public int getCorePoolSize() {
        synchronized (this.poolSizeMonitor) {
            return this.corePoolSize;
        }
    }

    /**
     * Set the ThreadPoolExecutor's maximum pool size. Default is <code>Integer.MAX_VALUE</code>.
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: