Created
December 23, 2017 17:37
-
-
Save chathurangat/192239d739847827b4d1b5825b3fe2b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Application | |
{ | |
public static void main(String[] args) | |
{ | |
System.out.println("main thread is started"); | |
ThreadA threadA = new ThreadA(); | |
threadA.start(); | |
ThreadB threadB = new ThreadB(); | |
threadB.start(); | |
System.out.println("main thread completed"); | |
} | |
} | |
class ThreadA extends Thread | |
{ | |
public void run() | |
{ | |
System.out.println("ThreadA is running"); | |
for(int index=0;index<5;index++) | |
{ | |
System.out.println("ThreadA running on ["+index+"]"); | |
if(index==2){ | |
System.out.println("ThreadA calls Thread.yield() "); | |
Thread.yield(); | |
} | |
} | |
System.out.println("ThreadA completed"); | |
} | |
} | |
class ThreadB extends Thread | |
{ | |
public void run() | |
{ | |
System.out.println("ThreadB is running"); | |
for(int index=0;index<5;index++){ | |
System.out.println("ThreadB running on ["+index+"]"); | |
} | |
System.out.println("ThreadB completed"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment