taskexecutordemo.java
来自「随书光盘:精通Sping 2.0 的随书源代码」· Java 代码 · 共 47 行
JAVA
47 行
package test;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.generic.GenericBeanFactoryAccessor;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.task.TaskExecutor;
/**
*
* @author worldheart
*
*/
public class TaskExecutorDemo {
protected static final Log log = LogFactory.getLog(TaskExecutorDemo.class);
public static void main(String[] args) throws InterruptedException {
AbstractApplicationContext aac = new ClassPathXmlApplicationContext("ac1.xml");
aac.registerShutdownHook();
GenericBeanFactoryAccessor gbfa = new GenericBeanFactoryAccessor(aac);
TaskExecutor te = gbfa.getBean("syncTaskExecutor");
// TaskExecutor te = new SyncTaskExecutor();
te.execute(new LogRunner());
te = gbfa.getBean("simpleAsyncTaskExecutor");
te.execute(new LogRunner());
te = gbfa.getBean("threadPoolTaskExecutor");
te.execute(new LogRunner());
te = gbfa.getBean("simpleThreadPoolTaskExecutor");
te.execute(new LogRunner());
te = gbfa.getBean("timerTaskExecutor");
te.execute(new LogRunner());
Thread.sleep(2000);
System.exit(0);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?