• 大小: 2.01MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-09-12
  • 语言: 其他
  • 标签: spring  线程池  

资源简介

线程池例子线程池例子线程池例子线程池例子

资源截图

代码片段和文件信息

package com.baidu.phl.executor;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathxmlApplicationContext;
import org.springframework.core.task.TaskExecutor;

public class Test {
private static Log log = LogFactory.getLog(Test.class);

private static TaskExecutor taskExecutor;

public static void main(String[] args) {
// 初始化工作只能运行一次;运行多次的话,会启动多个服务
ApplicationContext context = new ClassPathxmlApplicationContext(“applicationContext.xml“);
log.info(“hello commons-logging!“);
taskExecutor = context.getBean(“taskExecutor“ TaskExecutor.class);

for (int i = 0; i < 500; i++) {
// 此处用匿名类实现朋友们可以用其他方式实现
taskExecutor.execute(new Runnable() {
public void run() {
log.info(“hello spring “ + TaskExecutor.class.getName());
try {
Thread.currentThread().sleep(500);// 为了效果明显所以在这延迟一下
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
}

}
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2011-02-22 19:53  spring3.0.5_TaskExecutor\
     文件         793  2011-02-22 18:41  spring3.0.5_TaskExecutor\.classpath
     文件         400  2011-02-22 18:08  spring3.0.5_TaskExecutor\.project
     目录           0  2011-02-22 19:53  spring3.0.5_TaskExecutor\bin\
     文件        1246  2011-02-22 18:58  spring3.0.5_TaskExecutor\bin\applicationContext.xml
     目录           0  2011-02-22 19:53  spring3.0.5_TaskExecutor\bin\com\
     目录           0  2011-02-22 19:53  spring3.0.5_TaskExecutor\bin\com\baidu\
     目录           0  2011-02-22 19:53  spring3.0.5_TaskExecutor\bin\com\baidu\phl\
     目录           0  2011-02-22 19:53  spring3.0.5_TaskExecutor\bin\com\baidu\phl\executor\
     文件        1243  2011-02-22 19:18  spring3.0.5_TaskExecutor\bin\com\baidu\phl\executor\Test$1.class
     文件        1572  2011-02-22 19:18  spring3.0.5_TaskExecutor\bin\com\baidu\phl\executor\Test.class
     文件         320  2011-02-09 13:18  spring3.0.5_TaskExecutor\bin\commons-logging.properties
     文件         509  2011-01-17 10:21  spring3.0.5_TaskExecutor\bin\log4j.properties
     目录           0  2011-02-22 19:53  spring3.0.5_TaskExecutor\doc\
     文件        2854  2011-02-22 19:16  spring3.0.5_TaskExecutor\doc\readme.txt
     目录           0  2011-02-22 19:53  spring3.0.5_TaskExecutor\lib\
     文件       60841  2011-01-31 09:17  spring3.0.5_TaskExecutor\lib\commons-logging-1.1.1.jar
     文件      481534  2010-09-13 18:42  spring3.0.5_TaskExecutor\lib\log4j-1.2.16.jar
     文件       53082  2011-01-31 09:31  spring3.0.5_TaskExecutor\lib\org.springframework.asm-3.0.5.RELEASE.jar
     文件      555410  2011-01-31 09:17  spring3.0.5_TaskExecutor\lib\org.springframework.beans-3.0.5.RELEASE.jar
     文件      668861  2011-01-31 09:17  spring3.0.5_TaskExecutor\lib\org.springframework.context-3.0.5.RELEASE.jar
     文件      382442  2011-01-31 09:17  spring3.0.5_TaskExecutor\lib\org.springframework.core-3.0.5.RELEASE.jar
     文件      169752  2011-01-31 09:31  spring3.0.5_TaskExecutor\lib\org.springframework.expression-3.0.5.RELEASE.jar
     目录           0  2011-02-22 19:53  spring3.0.5_TaskExecutor\src\
     文件        1246  2011-02-22 18:58  spring3.0.5_TaskExecutor\src\applicationContext.xml
     目录           0  2011-02-22 19:53  spring3.0.5_TaskExecutor\src\com\
     目录           0  2011-02-22 19:53  spring3.0.5_TaskExecutor\src\com\baidu\
     目录           0  2011-02-22 19:53  spring3.0.5_TaskExecutor\src\com\baidu\phl\
     目录           0  2011-02-22 19:53  spring3.0.5_TaskExecutor\src\com\baidu\phl\executor\
     文件        1208  2011-02-22 19:18  spring3.0.5_TaskExecutor\src\com\baidu\phl\executor\Test.java
     文件         320  2011-02-09 13:18  spring3.0.5_TaskExecutor\src\commons-logging.properties
............此处省略1个文件信息

评论

共有 条评论