//thread를 이용해보자

package thread;

public class threadTest1 extends Thread
{
String str;
int n;
public threadTest1(String str,int n)
{
this.str=str;
this.n=n;
}

public void run()
{
for(int i=1;i<=n;i++)
{
System.out.println(i+":"+str);
}
}
/**
* @param args
*/
public static void main(String[] args)
{
threadTest1 th1= new threadTest1("1번 쓰레드",30);
threadTest1 th2= new threadTest1("2번 쓰레드",30);
threadTest1 th3= new threadTest1("3번 쓰레드",30);
threadTest1 th4= new threadTest1("4번 쓰레드",30);
th1.start();
th2.start();
th3.start();
th4.start();
//run 대신 start를 사용하면 순차적으로 실행되지 않는 것을 볼 수 있다.
}

}

Posted by 커널제로

본 블로그는 페이스북 댓글을 지원합니다.

,