Thread priority Example2

package threaddemo;
class MyThread11 extends Thread {
	MyThread11(String s) {
		super(s);
		start();
	}
	public void run() {
		for (int i = 0; i < 3; i++) {
			Thread cur = Thread.currentThread();
			cur.setPriority(Thread.MIN_PRIORITY);
			int p = cur.getPriority();
			System.out.println("Thread Name  :"
					+ Thread.currentThread().getName());
			System.out.println("Thread Priority  :" + p);
		}
	}
}
class MyThread2 extends Thread {
	MyThread2(String s) {
		super(s);
		start();
	}

	public void run() {
		for (int i = 0; i < 3; i++) {
			Thread cur = Thread.currentThread();
			cur.setPriority(8);
			int p = cur.getPriority();
			System.out.println("Thread Name  :"
					+ Thread.currentThread().getName());
			System.out.println("Thread Priority  :" + p);
		}
	}
}
public class ThreadPriority {
	public static void main(String args[]) {
		MyThread11 m1 = new MyThread11("My Thread 1");
		MyThread2 m2 = new MyThread2("My Thread 2");
		Thread.currentThread().setPriority(4);
		System.out.println("main");
	}
}

Download

Thread Source Code

Thread by extending Thread class
Thread by implementing Runnable interface
Multithread by implementing Runnable interface
Thread Intercommunication
Thread Join Example
Thread Join Example
Main Thread information
Multithreaded Example
Thread Priority
Thread Priority
Thread yield example


Write your Comment

Name :
Email Id : [ We will not publish your email id ]
Your Comment : [ Maximum 200 chars ]
Enter Security code