Results 1 to 1 of 1
Thread: How to get/set thread priority
-
How to get/set thread priority
This Java tip shows how to get/set the priority of a thread.
Java Code:public class SetPriority extends Object { private static Runnable makeRunnable() { Runnable r = new Runnable() { public void run() { for (int i = 0; i < 5; i++) { Thread t = Thread.currentThread(); System.out.println("in run() - priority=" + t.getPriority() + ", name=" + t.getName()); try { Thread.sleep(2000); } catch (InterruptedException x) { } } } }; return r; } public static void main(String[] args) { Thread threadA = new Thread(makeRunnable(), "threadA"); threadA.setPriority(8); threadA.start(); Thread threadB = new Thread(makeRunnable(), "threadB"); threadB.setPriority(2); threadB.start(); Runnable r = new Runnable() { public void run() { Thread threadC = new Thread(makeRunnable(), "threadC"); threadC.start(); } }; Thread threadD = new Thread(r, "threadD"); threadD.setPriority(7); threadD.start(); try { Thread.sleep(3000); } catch (InterruptedException x) { } threadA.setPriority(3); System.out.println("in main() - threadA.getPriority()=" + threadA.getPriority()); } }
Similar Threads
-
data from the main/GUI thread to another runnin thread...
By cornercuttin in forum Threads and SynchronizationReplies: 2Last Post: 04-23-2008, 10:30 PM -
How to implement Priority queue with Java
By Java Tip in forum java.langReplies: 0Last Post: 04-12-2008, 08:49 PM -
what is the Priority for execution of Interface class and a Abstract class
By Santoshbk in forum Advanced JavaReplies: 0Last Post: 04-02-2008, 07:04 AM -
If JNI thread call the java object in another thread, it will crash.
By skaterxu in forum Advanced JavaReplies: 0Last Post: 01-28-2008, 07:02 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks