- If a Thread don't want to perform any operation for a particular amount of time then we should go for sleep() method.
- public static native void sleep(long ms) throws InterruptedException
- public static void sleep(long ms,int ns)throws InterruptedException
Example:
class ThreadJoinDemo
{
public static void main(String[] args)throws
InterruptedException
{
System.out.println("P");
Thread.sleep(3000);
System.out.println("K");
Thread.sleep(3000);
System.out.println("N");
}
}
|
Output:
PK
N
Thanks..!!
No comments:
Post a Comment