首页文章正文

Thread.sleep,sleep()

sleep是什么意思 2024-01-08 14:12 845 墨鱼
sleep是什么意思

Thread.sleep,sleep()

Thread.sleep,sleep()

Sleep5s");///Threadenterssleep5sThread.sleep(5000L);}catch(InterruptedExceptione){System.out.println("CaughtInterruptedException异常!);System.out.println("Viewt1.thread1.Thread.sleep(500)2 .Thread.sleep(1000)4.Causeanalysis1.Safepoint2.Sourcecodeanalysis3.JVMparameters4.GClogcapture5.JVMsourcecodepositioning5.intandlongone,

1.静态方法:Thread.sleep(1000)2.参数为毫秒3.功能:让当前线程进入睡眠状态,进入"阻塞状态",放弃CPU时间片,让其他线程使用。 这行代码出现在线程A中,线程A的Thread.sleep()方法的作用是让当前线程休眠一段时间。例如:Thread.sleep(1000)使线程休眠1000毫秒,即1秒,但实际情况线程等待时间始终大于1000毫秒

╯▂╰ thread.setName("ThreadProcess");thread.start();for(inti=0;i<10;i++){System.out.println(Thread.currentThread().getName()+"-->"+ i);//阻塞主线程并睡眠一秒Thre因此Thread.Sleep(0)的作用就是"触发操作系统立即重新启动CPU竞争"。 竞争的结果可能是当前线程仍然获得CPU控制权,也可能被其他线程取代以获得CPU控制权。 这

Thread.sleep方法允许线程休眠;那么本章将探索sleep方法的源代码。 Thread.sleep方法有两个重载方法,sleep(毫秒)和sleep(毫秒、纳秒),但最终还是调用了sleep方法。该方法不调用Thread.sleep。ApplyThread.sleep.函数:调用Thread.sleep后,线程进入sleep状态,让出CPU,等待超时时间到期,安排运行再次由CPU。 我们先看Thread.java中的定义:

对于同样的时间表达式,TimeUnit显然要清晰得多。强烈建议在使用Thread.sleep的地方使用TimeUnit,因为TimeUnit可以完成sleep能做的所有事情。而4.sleep()是Thread类的静态(static)方法,因此它不能改变对象的机器锁。因此,当Synchronized块中调用Sleep()方法时,虽然线程休眠了,但对象的机器锁不存在锁或被子

后台-插件-广告管理-内容页尾部广告(手机)

标签: sleep()

发表评论

评论列表

黑豹加速器 Copyright @ 2011-2022 All Rights Reserved. 版权所有 备案号:京ICP1234567-2号