/*
public class ThreadPriority implements Runnable{
// run() method
public void run() {
for( int i=1 ; i<21 ; i++ ) {
// thread의 이름과 정수 출력
System.out.println( Thread.currentThread().getName() + " number = " + i );
}
}
public static void main( String[] args ) {
// 객체 생성
ThreadPriority tl = new ThreadPriority();
// 첫번째 Thread 생성
Thread first = new Thread( tl, "first" );
// 두번째 Thread 생성
Thread second = new Thread( tl, "second" );
// 세번째 Thread 생성
Thread third = new Thread( tl, "third" );
// thread의 우선순위를 출력
System.out.println( "first priority = " + first.getPriority() );
System.out.println( "first priority = " + first.getPriority() );
System.out.println( "second priority = " + second.getPriority() );
System.out.println( "third priority = " + third.getPriority() );
System.out.println( Thread.currentThread() + " priority = " +
Thread.currentThread().getPriority() );
}
}**/
public class ThreadPriority implements Runnable{
// run() method
public void run() {
for( int i=1 ; i<21 ; i++ ) {
// thread의 이름과 정수 출력
System.out.println( Thread.currentThread().getName() + " number = " + i );
}
}
public static void main( String[] args ) {
// 객체 생성
ThreadPriority tl = new ThreadPriority();
// 첫번째 Thread 생성
Thread first = new Thread( tl, "first" );
// 두번째 Thread 생성
Thread second = new Thread( tl, "second" );
// 세번째 Thread 생성
Thread third = new Thread( tl, "third" );
// thread의 우선순위를 출력
System.out.println( "first priority = " + first.getPriority() );
System.out.println( "second priority = " + second.getPriority() );
second.setPriority(Thread.MAX_PRIORITY);
//=second.setPriority(Thread.10);
System.out.println( "third priority = " + third.getPriority() );
System.out.println( Thread.currentThread() + " priority = " +
Thread.currentThread().getPriority() );
}
}
'새로워지기 > 서른의 생활코딩' 카테고리의 다른 글
ex8) java_thread (0) | 2012.03.04 |
---|---|
ex7) java_thread (0) | 2012.03.04 |
ex5) java_thread (0) | 2012.02.27 |
ex4) java_thread (0) | 2012.02.27 |
ex3) java_thread (0) | 2012.02.27 |
댓글