Browse Source

source code modify

tobby48 3 years ago
parent
commit
8211a05100

+ 0
- 18
src/kr/co/swh/lecture/java/scene4/LambdaInterface.java View File

@@ -1,18 +0,0 @@
1
-package kr.co.swh.lecture.java.scene4;
2
-
3
-/**
4
- * <pre>
5
- * kr.co.swh.lecture.java.scene4 
6
- * LambdaInterface.java
7
- *
8
- * 설명 :	람다 함수형 인터페이스
9
- * </pre>
10
- * 
11
- * @since : 2019. 3. 13.
12
- * @author : tobby48
13
- * @version : v1.0
14
- */
15
-@FunctionalInterface
16
-interface LambdaInterface {
17
-	public int sum(int x, int y);
18
-}

+ 4
- 0
src/kr/co/swh/lecture/java/scene4/LambdaMain.java View File

@@ -12,6 +12,10 @@ package kr.co.swh.lecture.java.scene4;
12 12
  * @author : tobby48
13 13
  * @version : v1.0
14 14
  */
15
+@FunctionalInterface
16
+interface LambdaInterface {
17
+	public int sum(int x, int y);
18
+}
15 19
 public class LambdaMain {
16 20
 	public static void main(String[] args) {
17 21
 		LambdaInterface add = (int x, int y) -> x + y;

+ 0
- 25
src/kr/co/swh/lecture/java/scene4/PlusAnnotation.java View File

@@ -1,25 +0,0 @@
1
-package kr.co.swh.lecture.java.scene4;
2
-
3
-import java.lang.annotation.ElementType;
4
-import java.lang.annotation.Retention;
5
-import java.lang.annotation.RetentionPolicy;
6
-import java.lang.annotation.Target;
7
-
8
-/**
9
- * <pre>
10
- * kr.co.swh.lecture.java.scene4 
11
- * PlusAnnotation.java
12
- *
13
- * 설명 :	어노테이션 만들기
14
- * </pre>
15
- * 
16
- * @since : 2019. 3. 13.
17
- * @author : tobby48
18
- * @version : v1.0
19
- */
20
-@Target({ElementType.METHOD})
21
-@Retention(RetentionPolicy.RUNTIME)
22
-public @interface PlusAnnotation {
23
-	String value() default "integer";
24
-	String plus() default "산술연산";
25
-}

+ 39
- 18
src/kr/co/swh/lecture/java/scene4/PlusAnnotationMain.java View File

@@ -1,5 +1,9 @@
1 1
 package kr.co.swh.lecture.java.scene4;
2 2
 
3
+import java.lang.annotation.ElementType;
4
+import java.lang.annotation.Retention;
5
+import java.lang.annotation.RetentionPolicy;
6
+import java.lang.annotation.Target;
3 7
 import java.lang.reflect.InvocationTargetException;
4 8
 import java.lang.reflect.Method;
5 9
 
@@ -15,25 +19,42 @@ import java.lang.reflect.Method;
15 19
  * @author : tobby48
16 20
  * @version : v1.0
17 21
  */
22
+@Target({ElementType.METHOD})
23
+@Retention(RetentionPolicy.RUNTIME)
24
+@interface PlusAnnotation {
25
+	String plus() default "산술연산";
26
+}
27
+class PlusService {
28
+	@PlusAnnotation()
29
+	public void numericOperator() {
30
+		System.out.println("numericOperator()");
31
+	}
32
+
33
+	@PlusAnnotation(plus = "문자열 결합")
34
+	public void stringOperator() {
35
+		System.out.println("stringOperator()");
36
+	}
37
+}
18 38
 public class PlusAnnotationMain {
19 39
 	public static void main(String[] args) {
20 40
 		//	PlusService 클래스에 있는 모든 메소드 얻기
21
-        Method[] methos = PlusService.class.getDeclaredMethods();
22
-        for (Method method : methos) {
23
-            //	메소드에 어노테이션이 적용되어 있다면
24
-            if(method.isAnnotationPresent(PlusAnnotation.class)) {
25
-                //	PlusAnnotation 객체를 얻은 후, 
26
-            	PlusAnnotation greetingAnnotation = method.getAnnotation(PlusAnnotation.class);
27
-                System.out.print(greetingAnnotation.plus());
28
-                try {
29
-                    //	PlusService의 메소드를 호출
30
-                    method.invoke(new PlusService());
31
-                } catch (IllegalAccessException e) {
32
-                    e.printStackTrace();
33
-                } catch (InvocationTargetException e) {
34
-                    e.printStackTrace();
35
-                }
36
-            }
37
-        }
38
-    }
41
+		Method[] methos = PlusService.class.getDeclaredMethods();
42
+		for (Method method : methos) {
43
+			//	메소드에 어노테이션이 적용되어 있다면
44
+			if(method.isAnnotationPresent(PlusAnnotation.class)) {
45
+				//	PlusAnnotation 객체를 얻은 후, 
46
+				PlusAnnotation greetingAnnotation = method.getAnnotation(PlusAnnotation.class);
47
+				System.out.print(greetingAnnotation.plus());
48
+				try {
49
+					//	PlusService의 메소드를 호출
50
+					//	invoke(호출대상객체, 메소드의 메개변수..)
51
+					method.invoke(new PlusService());
52
+				} catch (IllegalAccessException e) {
53
+					e.printStackTrace();
54
+				} catch (InvocationTargetException e) {
55
+					e.printStackTrace();
56
+				}
57
+			}
58
+		}
59
+	}
39 60
 }

+ 0
- 25
src/kr/co/swh/lecture/java/scene4/PlusService.java View File

@@ -1,25 +0,0 @@
1
-package kr.co.swh.lecture.java.scene4; 
2
-
3
-/**
4
- * <pre>
5
- * kr.co.swh.lecture.java.scene4 
6
- * PlusService.java
7
- *
8
- * 설명 :	어노테이션 적용 클래스
9
- * </pre>
10
- * 
11
- * @since : 2019. 3. 13.
12
- * @author : tobby48
13
- * @version : v1.0
14
- */
15
-public class PlusService {
16
-	@PlusAnnotation()
17
-    public void numericOperator() {
18
-        System.out.println("numericOperator()");
19
-    }
20
-
21
-    @PlusAnnotation(value = "string", plus = "문자열 결합")
22
-    public void stringOperator() {
23
-        System.out.println("stringOperator");
24
-    }
25
-}

+ 3
- 0
src/kr/co/swh/lecture/java/scene4/ThreadHigh1A.java View File

@@ -20,6 +20,7 @@ public class ThreadHigh1A extends Thread{
20 20
 	@Override
21 21
 	public void run() {
22 22
 		// TODO Auto-generated method stub
23
+		System.out.println(1);
23 24
 		synchronized(this){
24 25
 			while(true) {
25 26
 				count++;
@@ -35,7 +36,9 @@ public class ThreadHigh1A extends Thread{
35 36
 					e.printStackTrace();
36 37
 				}
37 38
 			}
39
+			System.out.println(2);
38 40
 			notify();
41
+			System.out.println(3);
39 42
 		}
40 43
 	}
41 44
 	

+ 8
- 8
src/kr/co/swh/lecture/java/scene4/ThreadHigh1Main.java View File

@@ -13,22 +13,22 @@ package kr.co.swh.lecture.java.scene4;
13 13
  * @version : v1.0
14 14
  */
15 15
 public class ThreadHigh1Main {
16
-	
17
-	
18 16
 	public static void main(String[] args) {
19 17
 		ThreadHigh1A threadA = new ThreadHigh1A();
20 18
 		threadA.start();
21 19
 		//	아래 주석코드를 풀고 다시 실행해보세요.
22
-//		try {
23
-//			Thread.sleep(100);
24
-//		} catch (InterruptedException e1) {
25
-//			// TODO Auto-generated catch block
26
-//			e1.printStackTrace();
27
-//		}
20
+		try {
21
+			Thread.sleep(100);
22
+		} catch (InterruptedException e1) {
23
+			// TODO Auto-generated catch block
24
+			e1.printStackTrace();
25
+		}
26
+		System.out.println(4);
28 27
 		synchronized (threadA) {
29 28
 			System.out.println("ThreadA 가 완료될때까지 Wait...");
30 29
 			try {
31 30
 				threadA.wait();
31
+				System.out.println(5);
32 32
 			} catch (InterruptedException e) {
33 33
 				// TODO Auto-generated catch block
34 34
 				e.printStackTrace();

+ 4
- 2
src/kr/co/swh/lecture/java/scene4/ThreadHigh1SecondMain.java View File

@@ -13,28 +13,30 @@ package kr.co.swh.lecture.java.scene4;
13 13
  * @version : v1.0
14 14
  */
15 15
 public class ThreadHigh1SecondMain {
16
-	
17
-	
18 16
 	public static void main(String[] args) {
19 17
 		ThreadHigh1A threadA = new ThreadHigh1A();
20 18
 		threadA.start();
21 19
 		ThreadHigh1A threadA2 = new ThreadHigh1A();
22 20
 		threadA2.start();
21
+		System.out.println(4);
23 22
 		synchronized (threadA) {
24 23
 			System.out.println("ThreadA 가 완료될때까지 Wait...");
25 24
 			try {
26 25
 				threadA.wait();
26
+				System.out.println(5);
27 27
 			} catch (InterruptedException e) {
28 28
 				// TODO Auto-generated catch block
29 29
 				e.printStackTrace();
30 30
 			}
31 31
 			System.out.println("5의 배수일때까지 합산은 : " + threadA.getSum());
32 32
 		}
33
+		System.out.println(6);
33 34
 		//	아래 코드에서 이상한 점은 없나요?
34 35
 		synchronized (threadA2) {
35 36
 			System.out.println("ThreadA 가 완료될때까지 Wait...");
36 37
 			try {
37 38
 				threadA2.wait();
39
+				System.out.println(8);
38 40
 			} catch (InterruptedException e) {
39 41
 				// TODO Auto-generated catch block
40 42
 				e.printStackTrace();

+ 0
- 53
src/kr/co/swh/lecture/java/scene4/ThreadHigh2.java View File

@@ -1,53 +0,0 @@
1
-package kr.co.swh.lecture.java.scene4;
2
-
3
-/**
4
- * <pre>
5
- * kr.co.swh.lecture.java.scene4
6
- * ThreadHigh2.java
7
- *
8
- * 설명 : 쓰레드 고급 두 번째 예제
9
- * </pre>
10
- * 
11
- * @since : 2021. 12. 23.
12
- * @author : tobby48
13
- * @version : v1.0
14
- */
15
-public class ThreadHigh2 extends Thread{
16
-	
17
-	private int sum = 0;
18
-	private ThreadHigh2SubJob otherThread;
19
-	
20
-	public ThreadHigh2(ThreadHigh2SubJob otherThread) {
21
-		// TODO Auto-generated constructor stub
22
-		this.otherThread = otherThread;
23
-	}
24
-	
25
-	@Override
26
-	public void run() {
27
-		// TODO Auto-generated method stub
28
-		synchronized(this){
29
-			for(int i=1; i<5; i++) {
30
-				sum += i;
31
-				System.out.println(i + "상위 쓰레드가 동작합니다.");
32
-				try {
33
-					Thread.sleep(1000);
34
-				} catch (InterruptedException e) {
35
-					// TODO Auto-generated catch block
36
-					e.printStackTrace();
37
-				}
38
-			}
39
-			try {
40
-				this.otherThread.join();
41
-			} catch (InterruptedException e) {
42
-				// TODO Auto-generated catch block
43
-				e.printStackTrace();
44
-			}
45
-			sum += this.otherThread.getSum();
46
-			notify();
47
-		}
48
-	}
49
-	
50
-	public int getSum() {
51
-		return sum;
52
-	}
53
-}

+ 61
- 1
src/kr/co/swh/lecture/java/scene4/ThreadHigh2Main.java View File

@@ -12,9 +12,69 @@ package kr.co.swh.lecture.java.scene4;
12 12
  * @author : tobby48
13 13
  * @version : v1.0
14 14
  */
15
-public class ThreadHigh2Main {
15
+class ThreadHigh2 extends Thread{
16
+	private int sum = 0;
17
+	private ThreadHigh2SubJob otherThread;
18
+	
19
+	public ThreadHigh2(ThreadHigh2SubJob otherThread) {
20
+		// TODO Auto-generated constructor stub
21
+		this.otherThread = otherThread;
22
+	}
16 23
 	
24
+	@Override
25
+	public void run() {
26
+		// TODO Auto-generated method stub
27
+		synchronized(this){
28
+			for(int i=1; i<5; i++) {
29
+				sum += i;
30
+				System.out.println(i + "상위 쓰레드가 동작합니다.");
31
+				try {
32
+					Thread.sleep(1000);
33
+				} catch (InterruptedException e) {
34
+					// TODO Auto-generated catch block
35
+					e.printStackTrace();
36
+				}
37
+			}
38
+			try {
39
+				this.otherThread.join();
40
+			} catch (InterruptedException e) {
41
+				// TODO Auto-generated catch block
42
+				e.printStackTrace();
43
+			}
44
+			sum += this.otherThread.getSum();
45
+			notify();
46
+		}
47
+	}
17 48
 	
49
+	public int getSum() {
50
+		return sum;
51
+	}
52
+}
53
+class ThreadHigh2SubJob extends Thread{
54
+	private int sum = 0;
55
+	
56
+	@Override
57
+	public void run() {
58
+		// TODO Auto-generated method stub
59
+		synchronized(this){
60
+			for(int i=5; i<11; i++) {
61
+				sum += i;
62
+				System.out.println(i + "하위 쓰레드가 동작합니다.");
63
+				try {
64
+					Thread.sleep(500);
65
+				} catch (InterruptedException e) {
66
+					// TODO Auto-generated catch block
67
+					e.printStackTrace();
68
+				}
69
+			}
70
+		}
71
+	}
72
+	
73
+	public int getSum() {
74
+		return sum;
75
+	}
76
+}
77
+public class ThreadHigh2Main {
18 78
 	public static void main(String[] args) {
19 79
 		ThreadHigh2SubJob subThread = new ThreadHigh2SubJob();
20 80
 		subThread.start();

+ 0
- 39
src/kr/co/swh/lecture/java/scene4/ThreadHigh2SubJob.java View File

@@ -1,39 +0,0 @@
1
-package kr.co.swh.lecture.java.scene4;
2
-
3
-/**
4
- * <pre>
5
- * kr.co.swh.lecture.java.scene4
6
- * ThreadHigh2SubJob.java
7
- *
8
- * 설명 : 쓰레드 고급 두 번째 예제
9
- * </pre>
10
- * 
11
- * @since : 2021. 12. 23.
12
- * @author : tobby48
13
- * @version : v1.0
14
- */
15
-public class ThreadHigh2SubJob extends Thread{
16
-	
17
-	private int sum = 0;
18
-	
19
-	@Override
20
-	public void run() {
21
-		// TODO Auto-generated method stub
22
-		synchronized(this){
23
-			for(int i=5; i<11; i++) {
24
-				sum += i;
25
-				System.out.println(i + "하위 쓰레드가 동작합니다.");
26
-				try {
27
-					Thread.sleep(500);
28
-				} catch (InterruptedException e) {
29
-					// TODO Auto-generated catch block
30
-					e.printStackTrace();
31
-				}
32
-			}
33
-		}
34
-	}
35
-	
36
-	public int getSum() {
37
-		return sum;
38
-	}
39
-}

+ 1
- 3
src/kr/co/swh/lecture/java/scene4/ThreadHigh3Main.java View File

@@ -79,6 +79,4 @@ class ThreadB extends Thread{
79 79
 			workObject.methodB();
80 80
 		}
81 81
 	}
82
-}
83
-
84
-
82
+}