Javaでのスレッド優先度の重要性?
マルチスレッドアプリケーションでは、各スレッドに優先順位が割り当てられます。プロセッサは、スレッドスケジューラによってスレッドに割り当てられます その優先度に基づいて、つまり、最も優先度の高いスレッドに最初にプロセッサが割り当てられます。 デフォルトの優先度 '5'の値を持つスレッドの 。 getPriority()を使用して、スレッドの優先度を取得できます。 Threadクラスのメソッド。
MAX_PRIORITY
これは、値が 10の最大スレッド優先度です。 。
NORM_PRIORITY
MIN_PRIORITY
これは、値が 1の最小スレッド優先度です。 。
public final int getPriority()
public class ThreadPriorityTest extends Thread {
public static void main(String[]args) {
ThreadPriorityTest thread1 = new ThreadPriorityTest();
ThreadPriorityTest thread2 = new ThreadPriorityTest();
ThreadPriorityTest thread3 = new ThreadPriorityTest();
System.out.println("Default thread priority of thread1: " + thread1.getPriority());
System.out.println("Default thread priority of thread2: " + thread2.getPriority());
System.out.println("Default thread priority of thread3: " + thread3.getPriority());
thread1.setPriority(8);
thread2.setPriority(3);
thread3.setPriority(6);
System.out.println("New thread priority of thread1: " + thread1.getPriority());
System.out.println("New thread priority of thread2: " + thread2.getPriority());
System.out.println("New thread priority of thread3: " + thread3.getPriority());
}
} Default thread priority of thread1: 5 Default thread priority of thread2: 5 Default thread priority of thread3: 5 New thread priority of thread1: 8 New thread priority of thread2: 3 New thread priority of thread3: 6
-
JavaでのSwingWorkerクラスの重要性は何ですか?
SwingWorker クラスを使用すると、非同期を実行できます タスク ワーカースレッド(長時間実行タスクなど)で、イベントディスパッチスレッド(EDT )からSwingコンポーネントを更新します。 ) タスクの結果に基づきます。 Java1.6バージョンで導入されました。 SwingWorkerクラス java.swing.SwingWorker クラスはタスクワーカーであり、時間のかかるタスクをバックグラウンドで実行します。 SwingWorker インスタンスは3つのスレッドと相互作用します。現在 スレッド 、ワーカースレッド 、およびイベントディスパッチスレッド(E
-
JavaでのSwingUtilitiesクラスの重要性は何ですか?
Javaでは、Swingコンポーネントが画面に表示された後、それらはイベント処理スレッドと呼ばれる1つのスレッドでのみ操作できます。 。別のブロックにコードを記述し、このブロックにイベントへの参照を与えることができます 処理 スレッド 。 SwingUtilities クラスには、 invokeAndWait()という2つの重要な静的メソッドがあります。 およびinvokeLater() コードのブロックへの参照をイベントに配置するために使用します キュー 。 構文 public static void invokeAndWait(Runnable doRun) throws Interr