Difference Between Similar Terms and Objects

Difference Between Sleep and Wait

Sleep vs Wait

Machines such as computers use artificial language to create programs, control them, and allow them to communicate instructions and express algorithms. This language is called programming language.

Before the advent of computers, programming languages had already been used in looms and pianos. As computer use became more common, there were now several programming languages being used.

There are several computer languages including high level languages such as: BASIC, C, C++, Fortran, Pascal, and Java. Each virtual machine and CPU has its own computer language, each with its own weaknesses and strengths, and every virtual machine runs a thread when started. This thread executes the application code in the program. It can make a program run faster and help in their performance and usefulness especially when multiple threads are used.

Virtual machines, such as the Java virtual machine, supports a multi-threading concept with higher priority threads executed first over lower priority threads ensuring the fair division of time processing.

It uses thread management methods which can create, control, and terminate the flow of controls or threads in a shared space. Two of these thread management methods are the wait and the sleep methods.

These two methods are separate. The sleep method controls the execution of the thread and delays the next action while the wait method does not control the execution of the thread to let other threads run.

The wait method is defined in the Object class and sends the current thread into the not runnable state. It is used together with notify and notifyAll methods to let the execution code of an object pause temporarily and to resume it later.

It works by calling on a lock object and letting the current thread synchronize with it. Wait will release the lock and will put the thread in the wait list and let other threads synchronize with it causing the original thread to wake up. The programmer determines the specific time when the execution starts again.

The sleep method, on the other hand, is defined as a static method. It delays the execution of threads and not objects as well as suspends the thread which is being executed. It sends current threads into the not runnable state for some period of time. It can affect the behavior of applications that are multi-threaded because it keeps the synchronization locks of the current thread. Once the thread is in a synchronized block, no other thread can enter the block.

Summary:

1.“Sleep” is a thread management method that is defined as a static method while “wait” is a thread management method which is defined in the Object class.
2.Sleep is a method that executes threads while wait is a method that executes objects.
3.Sleep keeps the synchronization locks of the current thread and influences the behavior of applications while wait does not.
4.Sleep controls the execution of the thread and does not allow other threads in a synchronized block while wait does not control the execution of the thread to let other threads run.


Search DifferenceBetween.net :

Custom Search


Help us improve. Rate this post! 1 Star2 Stars3 Stars4 Stars5 Stars
Loading...

Email This Post Email This Post : If you like this article or our site. Please spread the word. Share it with your friends/family.



Leave a Response

Please note: comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Articles on DifferenceBetween.net are general information, and are not intended to substitute for professional advice. The information is "AS IS", "WITH ALL FAULTS". User assumes all risk of use, damage, or injury. You agree that we have no liability for any damages.


See more about : ,
Protected by Copyscape Plagiarism Finder