ThreadPoolTaskExecutor

参考文档

http://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/html/scheduling.html

 

引入namespace

xmlns:task="http://www.springframework.org/schema/task" 

 

定义TaskExecutor

<bean id="checkTaskExecutor"

class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"

p:corePoolSize="20" p:maxPoolSize="30" p:queueCapacity="200"

p:keepAliveSeconds="100" />

 

注入Executor

@Autowired

public ThreadPoolTaskExecutor checkTaskExecutor;

 

实现线程

 

class CheckTask implements Runnable {

 

private String message;

 

public MessagePrinterTask(String message)

{

this.message = message;

}

 

publicvoid run()

{
//check logic here System.out.println(message);

}

}

 

执行Task

 checkTaskExecutor.execute(new CheckTask("check"));

 

 

 

 

你可能感兴趣的:(TaskExecutor)