Thread.Sleep(1)

问题描述

实际过程当中它沉睡了15.6毫秒,有什么办法把它替换掉,只沉睡1毫秒呢?

解决方案

解决方案二:
毫秒级的延时?坐等大神回答。
解决方案三:
不是延时,我找了两台电脑测试,貌似跟CPU有关,工控机上面是15.6,笔记本上面反而正常1毫秒2毫秒。
解决方案四:
Thread.Sleep(1)运行完,你把值打印出来也是需要时间的吧,这个时间根据电脑性能,负载情况。显示出来花费几毫秒也肯定是要的,我个人认为想要精确在毫秒级应该无法实现吧。PS:我是个新手,我的话只是个人想法,很可能不对。
解决方案五:
楼上说到了重点,我也比较想知道所谓的15.6是怎么得出来的
解决方案六:
CPU的响应时间,跟CPU有关,我看了windows定时器,但是设置了貌似没啥卵用。
解决方案七:
windows是多任务调度系统,所有的线程都在调度系统的调度下执行,从Thread需要首先等待系统的调度,获取执行权限后才会执行sleep()方法。时间是整个周期的时间。
解决方案八:
windows高精度定时器,你在网上搜一搜
解决方案九:
while(true){//检测时间}

时间: 2024-09-16 18:05:47

Thread.Sleep(1)的相关文章

android-如何处理 network on main thread exception 异常?

问题描述 如何处理 network on main thread exception 异常? 程序中设置了下面的两个类 class CallNetworkMethod extends AsyncTask<Void, Void, Void> { @Override protected Void doInBackground(Void... params) { if (TwitterUtils.isAuthenticated(prefs)) { sendTweet(); } else { Inte

Inter Thread Latency

原文地址:http://mechanical-sympathy.blogspot.com/2011/08/inter-thread-latency.html (移到墙内) Message rates between threads are fundamentally determined by the latency of memory exchange between CPU cores.   The minimum unit of transfer will be a cache line

5天不再惧怕多线程——第一天 尝试Thread

     原本准备在mongodb之后写一个lucene.net系列,不过这几天用到多线程时才发现自己对多线程的了解少之又少,仅仅停留在lock上面, 故这几天看了下线程参考手册结合自己的心得整理一下放在博客上作为自己的学习笔记.      好了,我们知道"负载"是一个很时尚,很牛X的玩意,往大处说,网站需要负载,数据库需要负载.往小处说,线程也需要负载,面对海量的 用户请求,我们的单线程肯定扛不住,那么怎么办,一定要负载,所以说多线程是我们码农必须要熟练掌握的一门技术.     在f

[转载]Thread.Sleep(0)妙用

原文地址http://blog.csdn.net/lgstudyvc/article/details/9337063 来自本论坛   我们可能经常会用到 Thread.Sleep 函数来使线程挂起一段时间.那么你有没有正确的理解这个函数的用法呢思考下面这两个问题 假设现在是 2008-4-7 12:00:00.000如果我调用一下 Thread.Sleep(1000) 在 2008-4-7 12:00:01.000 的时候这个线程会 不会被唤醒 某人的代码中用了一句看似莫明其妙的话Thread.

多线程Runnable和Thread产生线程

  http://dev.yesky.com/186/2547686.shtml public class Test { public static void main(String[] args) throws Exception{ MyThread mt = new MyThread(); mt.start(); mt.join(); Thread.sleep(3000); mt.start(); } } 当线程对象mt运行完成后,我们让主线程休息一下,然后我们再次在这个线程对象上启动线程.

Java Thread Programming 1.8.2 - Inter-thread Communication

  Missed Notification A missed notification occurs when threadB tries to notify threadA, but threadA is not yet waiting for the notification. In a multithreaded environment like Java, you don't have much control over which thread runs and for how lon

Java Thread Programming 1.8.3 - Inter-thread Communication

CubbyHole Example The class CubbyHole (see Listing 8.9) simulates a cubbyhole. A cubbyhole is a slot that can have only one item in it at a time. One thread puts an item into the slot and another thread takes it out. If a thread tries to put an item

Java Thread Programming 1.8.4 - Inter-thread Communication

Streaming Data Between Threads Using Pipes The java.io package provides many classes for writing and reading data to and from streams. Most of the time, the data is written to or read from a file or network connection. Instead of streaming data to a

Java Thread Programming 1.7 - Concurrent Access to Objects and Variables

access|object When multiple threads are interacting with an object, controls need to be in place to ensure that the threads don't adversely affect one another. This chapter deals with issues that can introduce subtle errors in your application. An ap

Java Thread Programming 1.8.1 - Inter-thread Communication

The Need for Inter-thread Signaling Through synchronization, one thread can safely change values that another thread will read. How does the second thread know that the values have changed? What if the second thread is waiting for the values to chang