java thread의 join 메소드 관련테스트

Contents

1 code
2 result

1 code #

package test01;

public class ThreadTest
{

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception
	{
		Mythread th = new ThreadTest().new Mythread();
		th.start();
		System.out.println("STARTED");
		th.join();
		System.out.println("FINISHED");
	}
	
	
	class Mythread extends Thread
	{
		public void run()
		{
			for(int i=0; i<3; i++){
				System.out.println(i);
				try{
					Thread.sleep(1000);
				}
				catch(InterruptedException ie){
					ie.printStackTrace();
				}
			}
		}
	}

}


2 result #

STARTED
0
1
2
FINISHED
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2008-08-27 17:32:32
Processing time 0.0063 sec