Syntax of sleep() method:
The Thread class provides two methods for sleeping a thread:
class MultiThreadDemo extends Thread{
public void run(){
for(int i=1;i<5;i++){
try{
Thread.sleep(500);
}catch(InterruptedException e){
System.out.println(e);
}
System.out.println("Dinesh on Java Thread Application "+i);
}
}
public static void main(String args[]){
MultiThreadDemo t1 = new MultiThreadDemo();
MultiThreadDemo t2 = new MultiThreadDemo();
t1.start();
t2.start();
}
}
Output:
As you know well that at a time only one thread is executed. If you sleep a thread for the specified time,the thread scheduler picks up another thread and so on.
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…