What is a java daemon thread
This article focuses on "what is the java daemon thread", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn "what is the java daemon thread"?
1. When other non-daemon threads finish, the daemon thread will end on its own.
2. Any thread can become a daemon thread. Declare that a thread is a daemon thread by calling Thread.setdaemon (). What threads have in common is that it only makes sense when non-daemon threads are still working.
Example
/ * Creates ten threads to search for the maximum value of a large matrix. * Each thread searches one portion of the matrix. * / public class TenThreads {private static class WorkerThread extends Thread {int max = Integer.MIN_VALUE; int [] ourArray; public WorkerThread (int [] ourArray) {this.ourArray = ourArray;} / / Find the maximum value in our particular piece of the array public void run () {for (int I = 0; I < ourArray.length) Max = Math.max (max, ourArray [I]);} public int getMax () {return max;}} public static void main (String [] args) {WorkerThread [] threads = new WorkerThread [10]; int [] [] bigMatrix = getBigHairyMatrix (); int max = Integer.MIN_VALUE / / Give each thread a slice of the matrix to work with for (int iTun0; I < 10; iBigMatrix +) {threads [I] = new WorkerThread (bigMatrix [I]); threads [I] .start ();} / / Wait for each thread to finish try {for (threads [I] .join () Max = Math.max (max, thread [I]. GetMax ());}} catch (InterruptedException e) {/ / fall through} System.out.println ("Maximum value was" + max);}} so far, I believe you have a deeper understanding of "what is a java daemon thread", you might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!