日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > java >内容正文

java

Java Thread类的最终void join()方法与示例

發(fā)布時(shí)間:2025/3/11 java 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java Thread类的最终void join()方法与示例 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

線程類最終void join() (Thread Class final void join())

  • This method is available in package java.lang.Thread.join().

    軟件包java.lang.Thread.join()中提供了此方法。

  • join() method is applicable when a thread wants to wait until completing some other thread then we should go for join() method of Thread class.

    join()方法 ,當(dāng)一個(gè)線程要等到完成一些其他線程那么我們就應(yīng)該去參加()Thread類的方法,方法是適用的。

  • This method is not static so we cannot access this method with the class name too.

    此方法不是靜態(tài)的,因此我們也無法使用類名訪問此方法。

  • This method is final we can't override this method in child class.

    此方法是最終方法,我們不能在子類中覆蓋此方法。

  • The return type of this method is void so it does not return anything.

    此方法的返回類型為void,因此它不返回任何內(nèi)容。

  • This method throws an InterruptedException so it is needed to handle exception either by try-catch or throws otherwise we will get a compile-time error.

    該方法拋出InterruptedException異常,因此需要通過try-catch或throws來處理異常,否則我們將獲得編譯時(shí)錯(cuò)誤。

For example: We have three threads [t1 – PreparedExamPaper ] ,[t2 – PrintingExamPaper],[t3- DistributingExamPaper] so will see what will happen.

例如:我們有三個(gè)線程[ t1 – PreparedExamPaper],[ t2 – PrintingExamPaper],[ t3 -DistributingExamPaper],因此將看到會(huì)發(fā)生什么。

Let suppose if a thread t1 executes, t2.join(), then thread t1 will entered into waiting for the state until t2 completes once t2 completes then t1 will continue its execution.

假設(shè)如果線程t1執(zhí)行t2.join() ,則線程t1將進(jìn)入等待狀態(tài),直到t2完成,一旦t2完成,則t1將繼續(xù)執(zhí)行。

Similarly, If a thread t2 executes, t3.join() then thread t2 will entered into waiting for the state until t3 completes once t3 completes, then t2 will continue its execution.

同樣,如果線程t2執(zhí)行t3.join(),則線程t2將進(jìn)入等待狀態(tài),直到t3完成后t3完成,然后t2將繼續(xù)執(zhí)行。

Syntax:

句法:

final void join(){}

Parameter(s):

參數(shù):

When we write t2.join(), so this line means currently executing thread will stop its execution and that thread will wait() for t2 completion.

當(dāng)我們編寫t2.join()時(shí) ,此行表示當(dāng)前正在執(zhí)行的線程將停止執(zhí)行,并且該線程將等待( 2)完成t2 。

Return value:

返回值:

The return type of this method is void, it does not return anything.

此方法的返回類型為void ,它不返回任何內(nèi)容。

Java程序演示join()方法的示例 (Java program to demonstrate example of join() method)

/* We will use Thread class methods so we are importing the package but it is not mandated because it is imported by default */import java.lang.Thread;class MyThread extends Thread {//Override run() method of Thread class public void run() {for (int i = 0; i < 5; ++i)System.out.println("We are in MyThread");try {Thread.sleep(500);} catch (Exception ex) {System.out.println(ex.getMessage());}} }class MainThread {public static void main(String[] args) throws Exception {MyThread mt = new MyThread();mt.start();/* Note -1*/mt.join();for (int j = 0; j < 5; ++j)System.out.println("We are in MainThread");} }

Note 1: If we comment /*mt.join()*/ in the above program then both threads will execute simultaneously we can't expect exact execution order and then we can't expect exact output.

注1:如果在上面的程序中注釋/*mt.join()*/,那么兩個(gè)線程將同時(shí)執(zhí)行,我們不能期望確切的執(zhí)行順序,也不能期望精確的輸出。

Output

輸出量

E:\Programs>javac MainThread.javaE:\Programs>java MainThread We are in MyThread We are in MyThread We are in MyThread We are in MyThread We are in MyThread We are in MainThread We are in MainThread We are in MainThread We are in MainThread We are in MainThread

翻譯自: https://www.includehelp.com/java/thread-class-final-void-join-method-with-example.aspx

總結(jié)

以上是生活随笔為你收集整理的Java Thread类的最终void join()方法与示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 午夜国产福利 | 久久人人澡 | 久久性生活视频 | 久久久精品小视频 | av黄| 无码国产精品96久久久久 | 国产精品300页 | 国产欧美一区二区三区白浆喷水 | 亚洲日本护士毛茸茸 | 波多野结衣视频在线 | 亚洲一线在线观看 | 人人看人人看 | 精品一区在线观看视频 | 亚洲在线一区二区 | 亚洲图片欧美另类 | 亚洲麻豆av | 亚洲AV成人无码久久 | 亚洲福利一区 | 色哟哟在线免费观看 | 亚洲看片网 | 欧美性理论片在线观看片免费 | 午夜日韩 | 日本黄色的视频 | 国产亚洲一区二区在线 | 欧美日韩激情在线一区二区三区 | 日韩不卡的av | 亚洲AV不卡无码一区二区三区 | 久久爱资源网 | www.成人网.com | 色婷婷成人 | 天天狠狠 | 免费一级特黄特色毛片久久看 | 男女免费网站 | 亚洲精品无码永久在线观看 | 国产av不卡一区二区 | 国产老头老太作爱视频 | 欧美精品久 | 一区二区成人在线观看 | 天天干天天谢 | 第一福利在线 | 精精国产xxxx视频在线播放 | 骚鸭av| 日韩亚洲欧美一区 | 国产喷水在线 | 懂色av| 另类捆绑调教少妇 | 免费福利视频在线观看 | 亚洲第一成人在线 | 日韩精品在线视频观看 | 国偷自产av一区二区三区 | 国产片久久 | 少妇高潮一区二区三区99欧美 | 少妇高潮毛片色欲ava片 | 亚洲性色图| 久久亚洲一区 | 国产粉嫩一区二区三区 | 亚洲免费久久 | 蜜桃视频成人 | 色欲久久久天天天综合网精品 | 视频国产一区 | 你懂的91 | 日本狠狠干 | 亚洲精品三区 | www一区二区三区 | 国产毛片不卡 | 成年人免费视频网站 | 免费一级特黄毛大片 | 91九色成人 | 超碰狠狠操 | 夜夜激情 | jizz少妇 | 日本人妻换人妻毛片 | 亚洲人人在线 | 国产免费高清 | 国产午夜精品福利视频 | 中文字幕一区视频 | 污污的视频网站在线观看 | 欧美视频在线免费 | 欧美又黑又粗 | 黄色小说在线观看视频 | 亚洲一区成人在线 | 国产中文字幕三区 | 日韩av一区在线观看 | 九九热视频这里只有精品 | 欧美三级在线观看视频 | 亚洲一区二区三区在线观看视频 | 成人久久av| 亚洲精品美女视频 | 欧美天堂在线 | 国产成人精品无码免费看夜聊软件 | 成人福利在线播放 | 国产愉拍 | 亚洲一区二区三区免费在线观看 | 中国三级视频 | 最新国产在线视频 | 在线观看免费av片 | 波岛野结衣 | 全黄一级裸体 | 真性中出|