UserLogin

From Progzoo
Revision as of 08:27, 12 December 2012 by Santhoshprasad (Talk | contribs) (Created page with "public class ThreadsDemo{ public static void main(String args[]){ EvenThread evenThread=new EvenThread(); OddThread oddThread=new OddThread(); evenThread.start(); ...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

public class ThreadsDemo{

public static void main(String args[]){


EvenThread evenThread=new EvenThread(); OddThread oddThread=new OddThread();

evenThread.start(); oddThread.start();

} }


class EvenThread extends Thread{

private String threadName=null; private int threadPriority=0;

EvenThread(){

this.threadName="Default"; this.priority=Thread.NORM_PRIORITY; }

EvenThread(String threadName,int threadPriority){

this.threadName=threadName; this.threadPriority=threadPriority; }

public void run(){


for(int i=0;i<=20;i+=2){

System.out.println(i);

try{

Thread.sleep(1000); }catch(Exception e){

e.printStackTrace(); } }

}

}


class OddThread extends Thread{

private String threadName=null; private int threadPriority=0;


OddThread(){

this.threadName="Default-Odd"; this.threadPriority=0; }

OddThread(String threadName,int threadPriority){

this.threadName=threadName; this.threadPriority=threadPriority; }

public void run(){

for(int ctr=1;ctr<22;ctr+=2){

System.out.println(ctr);

try{

Thread.sleep(1000); }catch(Exception e){

e.printStackTrace(); }

} }

}