当前位置: 代码迷 >> 高性能WEB开发 >> java的Executor种的性能
  详细解决方案

java的Executor种的性能

热度:153   发布时间:2013-07-01 12:33:04.0
java的Executor类的性能
近来开发一个机遇java的C/S架构的项目,需要考虑到并发量的问题,不知道Executor类的性能如何,能经得起多少的并发量呢?手写的线程池(足够好的话)会比它强吗
java

------解决方案--------------------
这个受你的服务器配置及应用场景影响了
发你段手工写的代码,你可以动态改变线程池的大小,保持连接的时间等参数,有点定制化的意思


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;
  相关解决方案