24 Ocak 2021 Pazar

Thread.setPriority metodu

Giriş
Açıklaması şöyle.
Every thread has a priority. Threads with higher priority are executed in preference to threads with lower priority.
Not 
Linux'da Thread önceliğini değiştirebilmek için JVM'i başlatırken iki tane parametre verilmes gerekiyor. Bunlar ThreadPriorityPolicy ve UseThreadPriorities. Şöyle yaparız
$ sudo java -XX:ThreadPriorityPolicy=1 -XX:+UseThreadPriorities ThreadPriorityTest &
Sabitler
Java 3 tane sabit veriyor. Açıklaması şöyle
The value can be anything between Thread.MAX_PRIORITY and Thread.MIN_PRIORITY (defined as 10 and 1 respectively). Default is Thread.NORM_PRIORITY with a value of 5.
Örnek
Şöyle yaparız
Thread t = new Thread();
t.setPriority(Thread.currentThread().getPriority() + 1);
t.start();
Örnek
Şöyle yaparız
Thread t1 = ...;
t1.setPriority(Thread.NORM_PRIORITY + 3);
      
Thread t2 = ...;
t2.setPriority(Thread.NORM_PRIORITY - 3);

Hiç yorum yok:

Yorum Gönder