In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you an example analysis of stop stop threads in Java multithreading. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.
Package com.stop;/** title: people line up at the ticket window of the railway station to buy train tickets. The door of Beijing West Railway Station 2. Open the ticket window 3. There are 10 tickets to Changsha in Beijing West Railway Station. Open 2 ticket windows, 5 suppose each window buys a ticket every 1 second. According to the nouns Person, railway station (Station), train ticket (Ticket), ticket window e is the thread of the railway station * / import java.util.*;public class TestTrain {public static void main (String [] args) {/ / the train west station opens Station station = new Station ("train west station") / / Open window / / Thread win1=station.openWindow ("normal window"); Thread win2 = station.openWindow ("student window"); / / window 1 start selling tickets / / set thread priority setPriority () / / win2.setPriority (Thread.MAX_PRIORITY); / / win1.start () Win2.start (); try {Thread.sleep (2000); / / 2 when the thread stops stop () win2.stop ();} catch (Exception e) {e.printStackTrace () } class Station implements Runnable {name of private String name;// Railway Station private String [] persons = {"Zhao Haiyang", "Wang Rui", "Song Sha", "Li Xinwei", "Xu Wenxiao", "Meng Lingqiang", "Wang David", "Li Baoqin", "Wang Hao"} / / people queuing up to buy tickets at the railway station private int i =-1; public Station (String name) {super (); this.name = name;} / / Open ticket window student window, ordinary window, military window / / ticket window is thread Thread public Thread openWindow (String name) {return new Thread (this, name) } / / Railway Station ticketing public void sale () {try {while (I < persons.length-1) {iPrefecture; String person = persons [I] System.out.println (person + "" + Thread.currentThread (). GetName () + "bought a train ticket from Beijing to Shanghai"); Thread.sleep (2000);}} catch (Exception e) {e.printStackTrace () } @ Override public void run () {/ / start selling tickets sale ();} public String getName () {return name;} public void setName (String name) {this.name = name }} the above is the analysis of the example of stop stopping threads in Java multithreading shared by Xiaobian. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
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.