JavaGian java tutorial and java interview question and answer

JavaGian , Free Online Tutorials, JavaGian provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, ajax, core java, sql, python, php, c language etc. for beginners and professionals.

Showing posts with label Thread-Sleep. Show all posts
Showing posts with label Thread-Sleep. Show all posts

Java Thread Sleep Example

7:41 AM
Some important points about sleep method are : It causes current executing thread to sleep for specific amount of time. Its accuracy depends on system timers and schedulers. It keeps the monitors it has acquired, so if it is called from synchronized context, no other thread can enter that block or method. If we call interrupt() method , it will wake up the sleeping thread. 1 2 3 4 5 6        synchronized ( lockedObject ) {           Thread . sleep ( 1000 ) ; // It does not release the lock on lockedObject.        // So either after 1000 miliseconds, current thread will wake up, or after we call        //t. interrupt() method.   Example: Create a class FirstThread.java as below. 1 2 3 4 5 6 7 8 9 10 11 12   package org . arpit . jav...

.