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 Thread2
Thread2 t2 = new Thread2();
// By calling start() so Thread start() will exceute
t2.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 notification
t2.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.java
D:\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)方法,包含示例相关推荐

  1. java 静态线程_Java线程类静态本机void yield()方法(带示例)

    线程类静态本机无效 yield()软件包java.lang.Thread.yield()中提供了此方法. yield()方法表示停止当前正在执行的线程,并为其他优先级相同的等待线程提供机会. 如果没有 ...

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

    线程类最终void join() (Thread Class final void join()) This method is available in package java.lang.Thre ...

  3. setpriority_Java Thread类的最终void setPriority(int priority)方法(带示例)

    setpriority 线程类最终void setPriority(int priority) (Thread Class final void setPriority(int priority)) ...

  4. java初始化实例化_Java对象的创建过程:类的初始化与实例化

    一.Java对象创建时机 我们知道,一个对象在可以被使用之前必须要被正确地实例化.在Java代码中,有很多行为可以引起对象的创建,最为直观的一种就是使用new关键字来调用一个类的构造函数显式地创建对象 ...

  5. java的equals方法_Java Duration类| 带示例的equals()方法

    java的equals方法 持续时间类equals()方法 (Duration Class equals() method) equals() method is available in java. ...

  6. java定义类属性方法_java定义类、属性、方法

    Java是面向对象的程序设计语言,Java语言提供了定义类.定义属性.方法等最基本的功能.类可被认为是一种自定义的数据类型,可以使用类来定义变量,所有使用类定义的变量都是引用变量,它们将会引用到类的对 ...

  7. java parsefloat 误差_Java Float类parseFloat()方法与示例

    Float类parseFloat()方法parseFloat()方法在java.lang包中可用. parseFloat()方法用于返回与给定String表示形式相对应的float值,换句话说,我们可 ...

  8. java newinstance 包_Java Class类 newInstance()方法及示例

    Class类newInstance()方法newInstance()方法在java.lang包中可用. newInstance()方法用于创建此Class对象表示的类的新实例. newInstance ...

  9. java arrays方法_Java工具类Arrays中不得不知的常用方法

    原标题:Java工具类Arrays中不得不知的常用方法 Arrays 数组操作集数组转List ---asList 这个被"普遍"称为数组转List的方法,可能是Arrays内大家 ...

最新文章

  1. Apache Storm 实时流处理系统通信机制源码分析
  2. 数据库常用面试题(SQL Server) (转载)
  3. TOJ 2857 Stockbroker Grapevine
  4. 洛谷P1879 [USACO06NOV]玉米田Corn Fields【状压dp】
  5. 分组背包(信息学奥赛一本通-T1272)
  6. torch.full 【输出大小为size内容为填充张量为fill_value的张量】
  7. XSD文件详解(以Maven为例)
  8. 从支付架构到风控报警,支付系统的设计如何环环相扣?
  9. 安卓版本客户端2.1
  10. 富士通陆宇澄:下半年推出主流价位超极本
  11. 诛仙服务器技能修改,2021年5月21日正式服技能修改公告
  12. iPad及BT4下的WEP破解实验与分析 | Network Security
  13. 第一篇 使用numpy创建数组(一维、多维)
  14. 读书笔记之一平米健身:硬派健身
  15. 24c02读程序C语言详解,24C02读写C语言程序
  16. Redis实战篇一 (短信登录)
  17. java后端如何主动发数据到前端_javaweb把后端数据返回到前端
  18. 职高计算机专业内容讲解,对职高计算机专业课程教学创新的探讨
  19. mac时间机器文件服务器,使用时间机器备份文件 - 处理文件和文件夹 - macOS使用手册...
  20. 「编程猫」融资13亿破记录 编程是如何风靡到小学生课程的?

热门文章

  1. linux 查看文件哈希码,使用linux的sha1sum命令查看效验文件哈希值命令
  2. 如何写一个作用域安全的构造函数
  3. 撸个微信小程序的省市区选择器
  4. Html5开发-使用Canvas绘制图片
  5. On Comparing Side-Channel Preprocessing Techniques for Attacking RFID Devices
  6. 基于JAX-WS的webService开发实例
  7. JAVA 常用框架和工具
  8. Linux下面的IO模型
  9. GridView 利用AspNetPager 分页时的自动编号
  10. Linux 2440 LCD 控制器