This site requires JavaScript, please enable it in your browser!
Greenfoot back
divinity
divinity wrote ...

2017/5/22

thread not running, cause of error

divinity divinity

2017/5/22

#
hi am doing thread running race the hare and tortoise timeless running race, but I change the variable from hare to cat and tortoise to dog, everything seem to going smooth except when it reach where it was interrupted method. can someone tell men why the compiler is not recognizing this error and how to fix it. here is the code
public class ThreadRace {
    
  
    
    public static void main(String[]args){
        
         Thread dog = new Thread(new ThreadRunner("Dog", 0,10));
         Thread cat = new Thread(new ThreadRunner("cat", 0, 10));
        
        dog.start();
        cat.start();
        
    }
     public static void finished(Thread winner){
        if(winner.isInterrupted()){
            return;
        }
        if(winner.getName().equals("Dog")){
            cat.interrupt(); this is where the error is(cat)
        }
        else if(winner.getName().equals("Cat")){
            dog.interrupt();this is where the error is(dog)
        }
        
    }
any help would be greatly appreciately and tell me how to fix it
You need to login to post a reply.