main 메서드가 있는 일반적인 자바 어플리케이션을 만들어서 아래와 같이 돌려보았다..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Tester implements Runnable { | |
private Log logger = LogFactory.getLog(Tester.class); | |
int i = 0; | |
public Tester(int i ) { | |
this.i = i; | |
} | |
public void run() { | |
try { | |
Thread.sleep(1000); | |
} catch (InterruptedException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
System.out.println(Thread.currentThread().getName() + " : [" + i + "]"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestMain { | |
private Log logger = LogFactory.getLog(TestMain.class); | |
public static void main(String[] args) { | |
for(int index = 0; index < 20; index++) { | |
new Thread(new Tester(index)).start(); | |
} | |
System.out.println("main end........................."); | |
} | |
} |
이렇게 해서 돌려보니까...
main end.........................
Thread-0 : [0]
Thread-6 : [6]
Thread-5 : [5]
Thread-2 : [2]
Thread-7 : [7]
Thread-1 : [1]
Thread-4 : [4]
Thread-3 : [3]
Thread-10 : [10]
Thread-8 : [8]
Thread-9 : [9]
Thread-13 : [13]
Thread-17 : [17]
Thread-12 : [12]
Thread-16 : [16]
Thread-14 : [14]
Thread-18 : [18]
Thread-11 : [11]
Thread-15 : [15]
Thread-19 : [19]
Thread-0 : [0]
Thread-6 : [6]
Thread-5 : [5]
Thread-2 : [2]
Thread-7 : [7]
Thread-1 : [1]
Thread-4 : [4]
Thread-3 : [3]
Thread-10 : [10]
Thread-8 : [8]
Thread-9 : [9]
Thread-13 : [13]
Thread-17 : [17]
Thread-12 : [12]
Thread-16 : [16]
Thread-14 : [14]
Thread-18 : [18]
Thread-11 : [11]
Thread-15 : [15]
Thread-19 : [19]
이렇게 나온다..대충 예상했던대로...
그런데 Junit 으로 아래와 같이 만들어서 돌려보니까..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestThread extends TestCase { | |
private Log logger = LogFactory.getLog(TestThread.class); | |
@Test | |
public void testM() { | |
for(int index = 0; index < 20; index++) { | |
new Thread(new Tester(index)).start(); | |
} | |
System.out.println("main end........................."); | |
} | |
} |
main end.........................
으로 끝나버린다. 이건 예상하지 못 한 결과...
어떤 차이로 이렇게 나오는건지..감도 못 잡것다.. ㅎㅎ;;;
junit이 test메서드를 실행하는 방법과의 차이 때문이겠지..?
풍대리님 계시면 바지 가랭이라도 붙잡고 늘어져서 여쭤봤을텐데.. ㅜ.ㅡ
가장 배워보고 싶은 부분 중 하나인데..
가장 어려운 부분 중 하나인것 같다. 그냥 냅둘까.. 쩝..