ThreadPoolTaskExecutor提高服务器响应速度

Spring配置文件




       
       
       
       
       
       
       
       
       
           
       



调用线程池

public static void startSendMsg(final long id, final String title, final String content, final int type) {
log.info("1-start sending startSendMsg");
ThreadPoolTaskExecutor taskExecutor = (ThreadPoolTaskExecutor) SpringUtil.getBean("taskExecutor");
taskExecutor.execute(new Runnable() {
public void run() {
log.info("2-taskExecutor.execute run start.");
try {
sendMsg(id, title, content, type);
} catch (Exception e) {
log.error("失败", e);
}
log.info("8-taskExecutor.execute run end.");
}
});
}


这个类似数据库连接池,减少创建线程,销毁线程时的开销,提高响应速度。

你可能感兴趣的:(java)