Skip to content

Commit aeada6c

Browse files
committed
线程池Ececutor的简单使用-启动LiftOff线程{@link LiftOff}
1 parent 8ba3329 commit aeada6c

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.javacore.thread;
2+
3+
import java.util.concurrent.ExecutorService;
4+
import java.util.concurrent.Executors;
5+
6+
/*
7+
* Copyright [2015] [Jeff Lee]
8+
*
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
*/
21+
22+
/**
23+
* @author Jeff Lee
24+
* @since 2015-11-2 17:21:04
25+
* 线程池Ececutor的简单使用-启动LiftOff线程{@link LiftOff}
26+
*/
27+
public class CachedThreadPool {
28+
public static void main(String[] args) {
29+
// 创建新线程的线程池
30+
ExecutorService exec = Executors.newCachedThreadPool();
31+
for (int i = 0 ; i < 5; i++)
32+
exec.execute(new LiftOff()); // 由线程池Ececutor决定执行给定的线程。
33+
// 顺序关闭,执行以前提交的线程,不接受新的线程。
34+
exec.shutdown();
35+
}
36+
}

0 commit comments

Comments
 (0)