티스토리 뷰

카테고리 없음

Thread(스레드) Test

사랑과사람 2009. 1. 21. 10:35
MyRunnable.java
public class MyRunnable implements Runnable
{
 public void run(){ go(); }
 public void go(){ doMore(); }
 public void doMore(){
  for(int i=0; i<10; i++) {
   System.out.println("thread A: " + i);
   }
  }
}

ThreadTestDrive.java

public class ThreadTestDrive
{
 public static void main(String[] args){
  Runnable threadJob = new MyRunnable();
  Thread myThread = new Thread(threadJob);
  myThread.start();
  for(int i=0; i<10; i++) {
   System.out.println("main thread : " + i);
  }
 }
}
Result

C:\javaExample>java ThreadTestDrive
main thread : 0
main thread : 1
main thread : 2
main thread : 3
main thread : 4
main thread : 5
thread A: 0
thread A: 1
thread A: 2
thread A: 3
thread A: 4
thread A: 5
thread A: 6
thread A: 7
main thread : 6
main thread : 7
main thread : 8
main thread : 9
thread A: 8
thread A: 9

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함