Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How Java controls thread termination

Shulou Source: shulou.com Published: 2022-06-01 04:25:30 10月02日 Update

This article introduces the knowledge of "how to control thread termination in Java". 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!

Public class Terminate implements Runnable {public boolean flag=true;public String name;public Terminate (String name) {this.name = name;} int iTuno alternate override public void run () {while (flag) {System.out.println (name+ "- >" + iTunes +);}} / / provide a method to change the identity void terminate () {this.flag=false;} public static void main (String [] args) {Terminate t=new Terminate ("Ronaldo") New Thread (t). Start (); for (int I = 0; I

< 100; i++) {if(i==80){t.terminate();//控制线程的终止//关键的一步骤 System.out.println("c罗gama over"); }System.out.println("main-->

"+ I);}" Java how to control thread termination "is introduced 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!

Tags: Threads control content more knowledge practicality learning next dilemma reality situation articles methods logos cases ribbons websites industries processes high quality Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi macOS Shulou Information Redmi Shulou Tech Info