Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the way java threads end?

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "how java threads end". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. The run () method that finishes running the thread.

2. The thread throws uncaptured Exception or Error.

3. Another thread calls the thread's stop () method (which has been discarded). They still exist, but you should not use them in new code and try to eliminate them from existing code.

Example

The public class ServerThread extends Thread {/ / volatile modifier is used to ensure that the latest value of this variable is always read by other threads public volatile boolean exit = false; @ Override public void run () {ServerSocket serverSocket = new ServerSocket (8080); while (! exit) {serverSocket.accept () / / blocking waiting for client messages...} public static void main (String [] args) {ServerThread t = new ServerThread (); t.start ();... T.exit = true; / / modify the flag bit, exit thread}} "what is the end of Java thread" content here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report