0

I tried to simulate a 400 meters race using multithreading concept.In this application totally 5 groups are created and they are named by country names,each group should have 2 players.First player is allowed to run for the first 200 meters followed by the next player in the group and the winner group has to be announced.Since i am a beginner in multithreading concept i tried to implement the first 200 meters process without concerning the next 200 meters process.But running the code doesnt print anything on the console.please help me to get through this...

RelayDemo.java

public class RelayDemo implements Runnable
{
    public void race()
    {
        for(int i=0;i<200;i++)
        {
            if(Thread.currentThread().getName()=="rakesh"||Thread.currentThread().getName()=="nathan"||Thread.currentThread().getName()=="max"||Thread.currentThread().getName()=="villiers"||Thread.currentThread().getName()=="decapro")
        {
            System.out.println("The distance covered by"+Thread.currentThread().getName()+"is "+i);
        }

    }
}
public void run()
{
    this.race();
}
}

ExcecuteRelay.java

public class ExcecuteRelay {

public static void main(String[] args) 
{
    RelayDemo r=new RelayDemo();
    ThreadGroup t1=new ThreadGroup("india");
    ThreadGroup t2=new ThreadGroup("australia");
    ThreadGroup t3=new ThreadGroup("usa");
    ThreadGroup t4=new ThreadGroup("africa");
    ThreadGroup t5=new ThreadGroup("france");
    Thread r1=new Thread(t1,r,"rakesh");
    Thread r2=new Thread(t1,r,"kishore");
    Thread r3=new Thread(t2,r,"nathan");
    Thread r4=new Thread(t2,r,"johnson");
    Thread r5=new Thread(t3,r,"max");
    Thread r6=new Thread(t3,r,"tim");
    Thread r7=new Thread(t4,r,"villiers");
    Thread r8=new Thread(t4,r,"duminy");
    Thread r9=new Thread(t5,r,"decapro");
    Thread r10=new Thread(t5,r,"lues");
    r1.start();
    r2.start();
    r3.start();
    r4.start();
    r5.start();
    r6.start();
    r7.start();
    r8.start();
    r9.start();
    r10.start();
        // TODO Auto-generated method stub

}

}
STF
  • 1,485
  • 3
  • 19
  • 36

0 Answers0