package com.myjava.threads;
class MySmpThread extends Thread{
public static int myCount = 0;
public void run(){
while(MySmpThread.myCount <= 10){
try{
System.out.println("Expl Thread: "+(++MySmpThread.myCount));
Thread.sleep(100);
} catch (InterruptedException iex) {
System.out.println("Exception in thread: "+iex.getMessage());
}
}
}
}
public class RunThread {
public static void main(String a[]){
System.out.println("Starting Main Thread...");
MySmpThread mst = new MySmpThread();
mst.start();
while(MySmpThread.myCount <= 10){
try{
System.out.println("Main Thread: "+(++MySmpThread.myCount));
Thread.sleep(100);
} catch (InterruptedException iex){
System.out.println("Exception in main thread: "+iex.getMessage());
}
}
System.out.println("End of Main Thread...");
}
}
class MySmpThread extends Thread{
public static int myCount = 0;
public void run(){
while(MySmpThread.myCount <= 10){
try{
System.out.println("Expl Thread: "+(++MySmpThread.myCount));
Thread.sleep(100);
} catch (InterruptedException iex) {
System.out.println("Exception in thread: "+iex.getMessage());
}
}
}
}
public class RunThread {
public static void main(String a[]){
System.out.println("Starting Main Thread...");
MySmpThread mst = new MySmpThread();
mst.start();
while(MySmpThread.myCount <= 10){
try{
System.out.println("Main Thread: "+(++MySmpThread.myCount));
Thread.sleep(100);
} catch (InterruptedException iex){
System.out.println("Exception in main thread: "+iex.getMessage());
}
}
System.out.println("End of Main Thread...");
}
}
Starting Main Thread... Main Thread: 1 Expl Thread: 2 Expl Thread: 3 Main Thread: 4 Expl Thread: 5 Main Thread: 5 Expl Thread: 6 Main Thread: 7 Main Thread: 8 Expl Thread: 9 Expl Thread: 11 Main Thread: 10 End of Main Thread...
No comments:
Post a Comment