spring线程池ThreadPoolTaskExecutor应用

来源:互联网 发布:excel找两列不同的数据 编辑:程序博客网 时间:2024/06/07 07:20

1、线程池配置文件

#一般采用properties配置

threadpool.corePoolSize=20
threadpool.maxPoolSize=50
threadpool.queueCapacity=20000



2、spring配置文件

<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"><property name="corePoolSize" value="${threadpool.corePoolSize}" /><property name="maxPoolSize" value="${threadpool.maxPoolSize}" /><property name="queueCapacity" value="${threadpool.queueCapacity}" /><property name="threadNamePrefix" value="resume_" /></bean>


3、java代码中注入线程池

    @Autowired    private ThreadPoolTaskExecutor taskExecutor;


启线程:

        taskExecutor.execute(new Runnable() {                        @Override            public void run() {                // TODO Auto-generated method stub                            }        });



原创粉丝点击