|
@@ -0,0 +1,57 @@
|
|
1
|
+package kr.co.swh.lecture.java.scene4;
|
|
2
|
+
|
|
3
|
+import java.util.ArrayList;
|
|
4
|
+import java.util.List;
|
|
5
|
+import java.util.concurrent.CountDownLatch;
|
|
6
|
+
|
|
7
|
+/**
|
|
8
|
+ * <pre>
|
|
9
|
+ * kr.co.swh.lecture.java.scene4
|
|
10
|
+ * ThreadBasic3.java
|
|
11
|
+ *
|
|
12
|
+ * 설명 : 쓰레드 기본예제 3 - sleep
|
|
13
|
+ * </pre>
|
|
14
|
+ *
|
|
15
|
+ * @since : 2017. 11. 17.
|
|
16
|
+ * @author : tobby48
|
|
17
|
+ * @version : v1.0
|
|
18
|
+ */
|
|
19
|
+public class ThreadBasic6 {
|
|
20
|
+
|
|
21
|
+ public void excute() {
|
|
22
|
+ int threadSize = 80;
|
|
23
|
+ List<Thread> threadList = new ArrayList<Thread>();
|
|
24
|
+ CountDownLatch latch = new CountDownLatch(threadSize);
|
|
25
|
+ for(int i=0; i<threadSize; i++) {
|
|
26
|
+ threadList.add(new Thread(new Runnable() {
|
|
27
|
+ @Override
|
|
28
|
+ public void run() {
|
|
29
|
+ // TODO Auto-generated method stub
|
|
30
|
+ System.out.println("쓰레드가 동작합니다.");
|
|
31
|
+ try {
|
|
32
|
+ Thread.sleep(1000);
|
|
33
|
+ }catch(Exception e) {
|
|
34
|
+
|
|
35
|
+ }
|
|
36
|
+ System.out.println("쓰레드가 종료합니다.");
|
|
37
|
+ latch.countDown();
|
|
38
|
+ }
|
|
39
|
+ }));
|
|
40
|
+ }
|
|
41
|
+ for(Thread t : threadList) {
|
|
42
|
+ t.start();
|
|
43
|
+ }
|
|
44
|
+ try {
|
|
45
|
+ latch.await();
|
|
46
|
+ } catch (InterruptedException e) {
|
|
47
|
+ // TODO Auto-generated catch block
|
|
48
|
+ e.printStackTrace();
|
|
49
|
+ }
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ public static void main(String[] args) {
|
|
53
|
+ ThreadBasic6 ex = new ThreadBasic6();
|
|
54
|
+ ex.excute();
|
|
55
|
+ System.out.println("메인함수가 종료합니다.");
|
|
56
|
+ }
|
|
57
|
+}
|