Multithreading in Java is a preemptible mechanism rather than a time-sharing mechanism. A thread can run, run, block, or die in the following states. A preemptible mechanism means that multiple threads are running, but only one thread is running.
Java. lang. ThreadOfSleep ()Method to pause the current thread for a period of time (unit: milliseconds ). Note that the parameters of the sleep () method cannot be negative. Otherwise, an IllegalArgumentException exception is thrown.
In addition,
These three functions are often obfuscated.From the operating system perspective, the OS maintains a ready queue (ready thread queue ). In addition, at a certain time, the cpu only serves the thread in the queue header of the ready queue.However,
Https://www.cnblogs.com/diegodu/p/7866073.htmlOneSleep is a thread-class method that causes this thread to pause execution for a specified time, giving the execution an opportunity to another thread, but the monitoring State remains, and then
Start today with a deep study of Java threads, starting with the 3 functions of sleep,join,interrupt.
Let's take a look at the functions of these 3 functions.
1,sleep: Is a static method of the thread class, which is to block the current thread, the
Reprint: http://blog.csdn.net/clam_clam/article/details/6803667The difference between sleep () and wait () Multithreading in Java is a preemptive mechanism rather than a time-sharing mechanism. Threads have the following states: Can run, run, block,
Js custom method implementation stay for several seconds sleep, jssleep
Js does not have its own sleep method. To sleep, define a method.
function sleep(numberMillis) { var now = new Date(); var exitTime = now.getTime() + numberMillis; while (true) {
OneSleep is a thread-class method that causes this thread to pause execution for a specified time, giving the execution an opportunity to another thread, but the monitoring State remains, and then automatically resumes after the call to sleep does
OneSleep is a thread-class method that causes this thread to pause execution for a specified time, giving the execution an opportunity to another thread, but the monitoring State remains, and then automatically resumes after the call to sleep does
Last time, I gave a general overview and summary of Java thread. Of course, most of them are in theory. This time I will explain two common and confusing methods in thread and use the example
Code ...
FDifferences
Sleep () methodSleep () causes
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.