當前位置:首頁 » 編程語言 » java多線程交替列印

java多線程交替列印

發布時間: 2023-09-14 00:34:40

java多線程編程,創建3個線程分別列印A,B和C,列印10次

{

="線程一列印A";
privateStringmessage;
privateStringnext;

publicTest(Stringmessage,Stringnext){
this.message=message;
this.next=慶彎next;
}

publicstaticvoidmain(String[]args){
newThread(newTest("線程一打搭差胡印A","線程二列印B")).start();
newThread(newTest("線程二打知攔印B","線程三列印C")).start();
newThread(newTest("線程三列印C","線程一列印A")).start();
}

publicvoidrun(){
for(inti=0;i<10;){
if(this.message.equals(Test.msg)){
System.out.println(this.message);
Test.msg=next;
i++;
}
}
}
}

這樣寫不需要同步代碼, 應該會更自然點

熱點內容
我的世界國服pvp伺服器ip地址 發布:2025-08-17 19:45:35 瀏覽:497
聊城電腦伺服器 發布:2025-08-17 19:34:59 瀏覽:407
互聯網編程語言 發布:2025-08-17 19:18:40 瀏覽:851
python主流框架 發布:2025-08-17 19:11:51 瀏覽:176
開源海量文件存儲 發布:2025-08-17 19:07:05 瀏覽:193
帶密碼的發票有什麼用 發布:2025-08-17 18:53:18 瀏覽:689
免費php模板下載 發布:2025-08-17 18:47:31 瀏覽:240
ubuntuphp開發 發布:2025-08-17 18:34:44 瀏覽:499
c語言小程序游戲 發布:2025-08-17 18:23:09 瀏覽:801
ios今日頭條源碼 發布:2025-08-17 18:23:02 瀏覽:311