📄 taskexecutordemo.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -