কম্পিউটার টিউটোরিয়াল

জাভাতে থ্রেড প্রায়োরিটির গুরুত্ব


মাল্টি-থ্রেডেড অ্যাপ্লিকেশনে, প্রতিটি থ্রেডকে একটি প্রায়োরিটি আসাইন করা হয়। প্রসেসর থ্রেড শিডিউলার দ্বারা থ্রেডের প্রায়োরিটি অনুযায়ী আসাইন করা হয়, অর্থাৎ সর্বোচ্চ প্রায়োরিটির থ্রেডকে প্রথমে প্রসেসর মিয়ে দেয়া হয়। একটি থ্রেডের ডিফল্ট প্রায়োরিটি হলো মান 5। আমরা Thread ক্লাসের getPriority() মেথড ব্যবহার করে থ্রেডের প্রায়োরিটি জানতে পারি।

Thread ক্লাসে থ্রেড প্রায়োরিটির জন্য তিনটি স্ট্যাটিক ভ্যালু ডিফাইন করা আছে:

MAX_PRIORITY

এটি সর্বোচ্চ থ্রেড প্রায়োরিটি যার মান 10।

NORM_PRIORITY

এটি ডিফল্ট থ্রেড প্রায়োরিটি যার মান 5।

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

  1. জাভা ৯-এ destroyForcibly() মেথডের গুরুত্ব

  2. জাভাতে StringReader ক্লাসের গুরুত্ব

  3. জাভাতে SwingWorker ক্লাসের গুরুত্ব কী?

  4. জাভাতে SwingUtilities ক্লাসের গুরুত্ব কী?