How to correctly use wait, policy, and policyall in Java
Wait, policy, and policyall are reserved keywords that are frequently used in multithreading, but they are not valued in actual development. This article describes the use of these
In the case of multithreading, because multiple threads of the same process share the same piece of storage space, there is also a serious problem of access to the conflict at the same time that it brings convenience. The Java language provides
Wait (), notify (), Notifyall () are not part of the thread class, but belong to the object base class, which means that each pair has wait (), notify (), Notifyall ()function. Because all have a lock on the image, the lock is the basis of each pair
In the case of multithreading, because multiple threads of the same process share the same piece of storage space, there is also a serious problem of access to the conflict at the same time that it brings convenience. The Java language provides
————————————————————————————————————————— the actual difference between the two is that sleep () is to let a thread pause for a period of time, and its control is determined by the current thread, that is, within the threads. Well, for example, What
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,
The sleep (), suspend (), and resume () methods are not recommended. We recommend that you use wait (), Policy (), and policyall ().
The sleep () method is used to stop a thread for a period of time. After the sleep interval expires, the thread may
This article from: http://blog.csdn.net/zyplus/article/details/6672775
After I opened a blog on csdn, I never published any article on it. It wasn't until I had a conversation with one of my predecessors that I discovered the importance of a
1, the difference between the two
The two methods come from different classes, namely thread and object
The main thing is that the sleep method does not release the lock, and the wait method frees the lock so that other threads can use
What is the difference between sleep () and wait ()?Sleep is a threading class (thread) method that causes this thread to pause execution for a specified time, giving the execution opportunity to other threads, but the monitoring state remains and
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.