কম্পিউটার

জাভাতে isDaemon() পদ্ধতির গুরুত্ব?


একটি ডেমন থ্রেড হল একটি নিম্ন-অগ্রাধিকার থ্রেড java-তে যা ব্যাকগ্রাউন্ডে চলে এবং বেশিরভাগই JVM দ্বারা তৈরি করা হয় ব্যাকগ্রাউন্ডের কাজ যেমন Garbage Collection(GC) করার জন্য। যদি কোনো ব্যবহারকারীর থ্রেড চলমান না হয় তবে ডেমন থ্রেড চললেও JVM প্রস্থান করতে পারে। একটি ডেমন থ্রেডের একমাত্র উদ্দেশ্য হল ব্যবহারকারীর থ্রেডগুলি পরিবেশন করা। isDaemon() থ্রেড ডেমন থ্রেড কি না তা নির্ধারণ করতে পদ্ধতি ব্যবহার করা যেতে পারে

সিনট্যাক্স

Public boolean isDaemon()

উদাহরণ

class SampleThread implements Runnable {
   public void run() {
      if(Thread.currentThread().isDaemon())
         System.out.println(Thread.currentThread().getName()+" is daemon thread");
      else
         System.out.println(Thread.currentThread().getName()+" is user thread");
   }
}
// Main class
public class DaemonThreadTest {
   public static void main(String[] args){
      SampleThread st = new SampleThread();
      Thread th1 = new Thread(st,"Thread 1");
      Thread th2 = new Thread(st,"Thread 2");
      th2.setDaemon(true); // set the thread th2 to daemon.
      th1.start();
      th2.start();
   }
}

আউটপুট

Thread 1 is user thread
Thread 2 is daemon thread

  1. জাভা কনকারেন্সি - join() পদ্ধতি

  2. জাভা কনকারেন্সি - sleep() পদ্ধতি

  3. জাভা কনকারেন্সি - yield() পদ্ধতি

  4. জাভা 9 এ DestroForcibly() পদ্ধতির গুরুত্ব?