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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

java void方法_Java对象类的最终void wait(long ms)方法,包含示例

發布時間:2023/12/1 java 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java void方法_Java对象类的最终void wait(long ms)方法,包含示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

java void方法

對象類最終無效等待(長毫秒) (Object Class final void wait(long ms))

  • This method is available in java.lang.Object.wait(long ms).

    此方法在java.lang.Object.wait(long ms)中可用。

  • This method causes the current thread to wait for a specified amount of time until another thread notification by calling notify() or notifyAll() method of the object.

    此方法使當前線程等待指定的時間,直到通過調用對象的notify()或notifyAll()方法發出另一個線程通知為止。

  • This method throws an InterruptedException when other thread interrupted current thread.

    當其他線程中斷當前線程時,此方法將引發InterruptedException 。

  • This method can't override because it is final.

    此方法是最終方法,因此無法覆蓋。

  • The time will be given in the method is of milliseconds.

    該方法將給出的時間以毫秒為單位。

Syntax:

句法:

final void wait(long ms){}

Parameter(s):

參數:

We can pass an object(How long a thread has to wait i.e. we have to mention time in milliseconds) as a parameter in the method of the Object class.

我們可以在Object類的方法中將一個對象(線程必須等待多長時間,即必須提到毫秒)作為參數傳遞。

Return value:

返回值:

The return type of this method is void that means this method returns nothing after execution.

該方法的返回類型為void ,這意味著該方法在執行后不返回任何內容。

Java程序演示對象類等待(長毫秒)方法的示例 (Java program to demonstrate example of Object Class wait(long ms) method)

import java.lang.Object;public class Thread1 {public static void main(String[] args) throws InterruptedException {// Create an object of Thread2Thread2 t2 = new Thread2();// By calling start() so Thread start() will exceutet2.start();Thread.sleep(1000);synchronized(t2) {System.out.println("Main thread trying to call wait()");// By calling wait() causes the current thread to wait // for 1000 milliseconds until another thread notificationt2.wait(1000);System.out.println("Main Thread get notification here");System.out.println(t2.total);}} }class Thread2 extends Thread {int total = 0;public void run() {synchronized(this) {System.out.println("Thread t2 starts notification");for (int i = 0; i < 50; ++i) {total = total + i;}System.out.println("Thread t2 trying to given notification");this.notify();}} }

Output

輸出量

D:\Programs>javac Thread1.javaD:\Programs>java Thread1 Thread t2 starts notification Thread t2 trying to given notification Main thread trying to call wait() Main Thread get notification here 1225

翻譯自: https://www.includehelp.com/java/object-class-final-void-wait-long-ms-method-with-example.aspx

java void方法

總結

以上是生活随笔為你收集整理的java void方法_Java对象类的最终void wait(long ms)方法,包含示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。