1 Star 0 Fork 0

firewaycoding/think_in_java

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ExecutorTestCase.java 1.16 KB
一键复制 编辑 原始数据 按行查看 历史
firewaycoding 提交于 2019-03-14 07:29 +08:00 . 本次应用修改:调整目录架构
package concurrency;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import junit.framework.TestCase;
/**
* 使用Executor
*
* 2018年 09月 16日 星期日
* fireway
*/
public class ExecutorTestCase extends TestCase {
public void testNewCachedThreadPool() {
ExecutorService exec = Executors.newCachedThreadPool();
for (int i = 0; i < 5; i++) {
exec.execute(new LiftOff());
}
exec.shutdown();
System.out.print("testNewCachedThreadPool Waiting for LiftOff! ");
}
public void testNewFixedThreadPool() {
ExecutorService exec = Executors.newFixedThreadPool(5);
for (int i = 0; i < 5; i++) {
exec.execute(new LiftOff());
}
exec.shutdown();
System.out.print("testNewFixedThreadPool Waiting for LiftOff! ");
}
public void testNewSingleThreadExecutor() {
ExecutorService exec = Executors.newSingleThreadExecutor();
for (int i = 0; i < 5; i++) {
exec.execute(new LiftOff());
}
exec.shutdown();
System.out.print("testNewSingleThreadExecutor Waiting for LiftOff! ");
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/firewaycoding/think_in_java.git
git@gitee.com:firewaycoding/think_in_java.git
firewaycoding
think_in_java
think_in_java
master

搜索帮助