In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
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!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.