Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Putting the current thread to sleep

I have a unit of work I'm doing in a thread (not the main thread). Under certain circumstances I would like to put this thread to sleep for 10 seconds. Is Thread.Sleep(10000) the most resource efficient way to do this?

like image 936
Hosea146 Avatar asked Oct 04 '11 16:10

Hosea146


1 Answers

Is Thread.Sleep(10000) the most resource efficient way to do this?

Yes in the sense that it is not busy-waiting but giving up the CPU.

But it is wasting a Thread. You shouldn't scale this to many sleeping threads.

like image 104
Henk Holterman Avatar answered Sep 21 '22 19:09

Henk Holterman