![](/img/trans.png)
[英]Perform the task using WebDriverWait and not thread.sleep()
[英]Effect of Thread.sleep on a runnable task waiting on windows to complete file creation/moving
我有一個條件,其中Windows文件夾上的文件移動/創建正在為任務繼續使用該路徑上的文件創建定時問題
因此,我正在使用線程.sleep(30ms)休眠運行該任務的守護進程線程,直到Windows正常運行,並且允許我的任務正常運行而沒有任何FileNotFoundException異常為止。
初始化類
Thread t = new Thread (processTask);
t.setdaemon(true)
t.start();
任務班
class ProcessTask() extends Runnable
{
Files.move(source, destination, copyoption);
Thread.sleep(30ms); //to wait for windows to complete move
new FileInputstream(sourceFile);
}
可以肯定地說thread.sleep(30ms)只休眠我當前的守護進程線程嗎? 有沒有辦法確認睡眠在哪里起作用
Thread.sleep()
影響當前線程。 它不會使其他線程進入睡眠狀態。
但是,對於程序邏輯,使用Thread.sleep()
絕不是一個好主意。 特別是在等待其他操作完成時。 這些應該通過通知機制來處理,而不是等待隨機數,並希望一切都會正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.