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 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方法

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/380311.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C和汇编----字符串

字符串是以空字符&#xff08;\0&#xff09;结尾的char类型数组。 0x01 定义字符串和初始化 用双引号括起来的内容称为字符串字面量&#xff0c;也叫字符串常量&#xff0c;双引号中的字符串和编译器自动加入\0字符&#xff0c;都作为字符串存储在内存中 #include "st…

出现此版本的sql server不支持用户实例登陆标志 问题的解决方法

场景: 开发工具vs2005 数据库 sql 2005加入了Enterprise Libraty后,新增了一个data access application block,在写ConnectString的时候,出现这个错误提示,解决办法:在连接属性的设置里边,点高级,将User Instance 设置为false,默认的true,所以才导致这个问题的出现.设置好后,重…

计算机编程输入与输出,计算机编程语言的发展与输入输出设备的使用

计算机编程语言的发展与输入输出设备的使用辽宁大学学报自然科学版第32卷 第2期 2005年JOURNALOFLIAONINGUNIVERSITYNaturalSciencesEditionVol.32 No.2 2005计算机编程语言的发展与输入输出设备的使用宋明杰3(辽宁大学信息科学与技术学院,辽宁沈阳110036)摘 要:在编程中涉…

大小写互换

描述 现在给出了一个只包含大小写字母的字符串&#xff0c;不含空格和换行&#xff0c;要求把其中的大写换成小写&#xff0c;小写换成大写&#xff0c;然后输出互换后的字符串。 输入 第一行只有一个整数m&#xff08;m<10),表示测试数据组数。 接下来的m行&#xff0c…

远控免杀专题1---基础篇

0x01 免杀概念 免杀&#xff0c;也就是反病毒与反间谍的对立面&#xff0c;英文为Anti-AntiVirus&#xff08;简写 Virus AV&#xff09;&#xff0c;逐字翻译就是反-反病毒&#xff0c;翻译为反病毒技术。 0x02 杀毒软件检测方法 1、扫描结束 扫描压缩包技术&#xff1a;即…

查询所有存储过程

--查询所有存储过程selectPr_Name as[存储过程], [参数]stuff((select&#xff0c;[Parameter]from( selectPr.Name asPr_Name,parameter.name Type.Name (convert(varchar(32),parameter.max_length))asParameter fromsys.procedures Pr leftjoinsys.parameters…

使用JavaScript中的示例编号MAX_VALUE属性

数字MAX_VALUE属性 (Number MAX_VALUE Property) MAX_VALUE Property is a Number property in JavaScript and it is used to get the maximum value of a number that is possible in JavaScript. MAX_VALUE属性是JavaScript中的Number属性&#xff0c;用于获取JavaScript中可…

文件复制器

文件复制器 2007.08.18.0地狱门神(F.R.C.)http://files.cnblogs.com/Rex/FileCopier.rar 本软件用于复制或更新一个文件夹中的文件到另一个文件夹中。 当你需要经常通过向移动硬盘复制文件来备份重要数据时&#xff0c;可能会遇到如下情况&#xff1a;(1)电脑USB接口过旧&#…

远控免杀专题2---msfvenom的隐藏参数

0x01 msfvenom简介 msfvenom是msfpayload和msfencode的结合体&#xff0c;与2015年6月8日取代了msfpayload和msfencode。在此之后&#xff0c;metasploit-framwork下面的msfpayload&#xff08;载荷生成器&#xff09;&#xff0c;msfencoder&#xff08;编码器&#xff09;&a…

转载CSDN - 从程序员到HR——面试经验分享

CSDN博客一周热文推荐&#xff0c;为您总结回顾过去一周的CSDN博客热门文章&#xff0c;推荐优质的博客作者&#xff0c;分享精华文章和优质博客。 [1] 谭海燕&#xff1a;北漂之惠普H3C面试经历 上一篇讲到了《北漂之百度面试》&#xff0c;今天跟大家分享我在H3C的面试经历。…

ai系统架构_人工智能中的模糊逻辑系统架构

ai系统架构The Fuzzy Logic System is a system which uses Fuzzy logic for reasoning. Fuzzy Logic is a very efficient method for performing human-like reasoning in conditions with uncertainty. 模糊逻辑系统是使用模糊逻辑进行推理的系统。 模糊逻辑是一种在不确定条…

魔力宝贝 服务器状态,魔力宝贝服务端standenemy的参数

格式&#xff1a;encount A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|A是触发战斗类型&#xff0c;这个参数主要用在StandEnemy的NPC参数里面&#xff0c;EventNPC脚本触发战斗有局限。这里详细解释下&#xff1a;触发战斗有2种方法&#xff1a;一种走着撞上去&#xff0c;一种站在…

Firefox中国即将成立,希望在华推行Web标准

Mozilla的首席技术官(vp engineering)Mike Schroepfer给Firefox的粉丝们带来一个好消息:Firefox在中国的负责人李宫昨日接到总部正式通知,将在中国成立公司.Mike称:“公司将设立在清华科技园,在Google、微软的旁边,不过一开始规模不会大,只有几个人.李宫将负责招兵买马.实际上,…

字母小游戏

描述 给你一个乱序的字符串,里面包含有小写字母(a–z)以及一些特殊符号&#xff0c;请你找出所给字符串里面所有的小写字母的个数&#xff0c; 拿这个数对26取余&#xff0c;输出取余后的数字在子母表中对应的小写字母(0对应z,1对应a&#xff0c;2对应b….25对应y)。 输入 第…

缅怀过去

这么多年再不会为你隐忍地哭泣再不会在深夜里独自缅怀我们青涩的年华再不会在伤害你之后把自己伤痕累累却仍然小心翼翼地藏着再不会为过去的你掉眼泪一切都已经成为过去 在你很久没有想我之后我也很久不再去想起你忘却只是唯一逃生的路因为太依赖我们之间真的只能如此了吗忙碌成…

远控免杀专题3---msf自免杀

0x01 免杀能力一览表 上面表中标识 √ 说明相应杀毒软件未检测出病毒&#xff0c;也就是代表了Bypass。为了更好的对比效果&#xff0c;大部分测试payload均使用msf的windows/meterperter/reverse_tcp模块生成。由于本机测试时只是安装了360全家桶和火绒&#xff0c;所以默认情…

苹果手机的计算机删除了怎么恢复,苹果手机电话删除了怎么恢复

在清理手机通讯录的时候&#xff0c;万一不小心误删了手机通讯录&#xff0c;怎么办。那么被删除的手机通讯录还能找回吗?答案是可以的&#xff0c;苹果手机通讯录删除了怎么恢复呢。苹果手机电话删除了怎么恢复一、从iCloud恢复步骤1、打开【设置】-【Apple ID】-【iCloud】&…

php字符串反转函数_PHP | 反转给定的字符串而不使用库函数

php字符串反转函数Given a string and we have to reverse it without using a library function. 给定一个字符串&#xff0c;我们必须不使用库函数而将其反转。 Example: 例&#xff1a; Input: "Hello world!"Output: "!dlrow olleH"Input: "Wel…

boost::regex学习(2)

四&#xff1a;regex_match例子代码学习1 我们经常会看一个字符串是不是合法的IP地址&#xff0c;合法的IP地址需要符合以下这个特征&#xff1a;xxx.xxx.xxx.xxx 其中xxx是不超过255的整数正则表达式找到上面的这种形式的字符串相当容易&#xff0c;只是判断xxx是否超过255就比…

C++ 随机数

#include < iostream> #include < ctime> #include < cstdlib> using namespace std; int main () { int i,j; // 设置种子 srand( (unsigned)time( NULL ) ); /* 生成 10 个随机数 */ for( i 0; i < 10; i ) { // 生成实际的随机数 j rand…