Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package runners_judge;
- import java.util.*;
- public class Judge implements Runnable
- {
- private static ArrayList<Runner> chart = new ArrayList<Runner>();
- public static synchronized void addRunner(Runner r)
- {
- if(r.hasArrived())
- chart.add(r);
- if(chart.size() == 1)
- System.out.println(r.toString() + " won the competition!");
- }
- public static synchronized void printChart()
- {
- for(int i = 0; i < chart.size(); i++)
- System.out.println(chart.get(i).toString() + " has reached position " + i);
- }
- public void run()
- {
- synchronized(this)
- {
- while(chart.isEmpty())
- {
- try
- {
- wait();
- }
- catch(InterruptedException e)
- {
- e.printStackTrace();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement