当前位置: 代码迷 >> J2SE >> Thread.Sleep(2hours)时,用什么办法让它成为sleep(1hours)的时间
  详细解决方案

Thread.Sleep(2hours)时,用什么办法让它成为sleep(1hours)的时间

热度:460   发布时间:2016-04-24 17:19:25.0
Thread.Sleep(2hours)时,用什么办法让它变成sleep(1hours)的时间
只是动态地减少这个sleep时间,怎么弄呀

------解决方案--------------------
Thread1: sleep(2hours);
Thread2: sleep(1hour) then interrupt Thread1;
------解决方案--------------------
把间隔时间设短啊,比如每次sleep5分钟,控制好循环次数不就OK了
------解决方案--------------------
我习惯 用 WaitForSingleObject
------解决方案--------------------
DWORD WaitForSingleObject(

HANDLE hHandle, // handle of object to wait for
DWORD dwMilliseconds // time-out interval in milliseconds
);


Parameters

hHandle

Identifies the object. For a list of the object types whose handles can be specified, see the following Remarks section.
Windows NT: The handle must have SYNCHRONIZE access. For more information, see Access Masks and Access Rights.

dwMilliseconds

Specifies the time-out interval, in milliseconds. The function returns if the interval elapses, even if the object 's state is nonsignaled. If dwMilliseconds is zero, the function tests the object 's state and returns immediately. If dwMilliseconds is INFINITE, the function 's time-out interval never elapses.

  相关解决方案