import java.util.*;

public class ThreadExample extends TimerTask {
	//A ThreadExample schedules a task, which prints a phrase 10 times when run
	
	private Timer timer;
	private String phrase;
	
	public ThreadExample(int startSeconds, String phrase){
		this.phrase = phrase;
		timer = new Timer();
		timer.schedule(this, startSeconds*1000);//schedules the task
	}
	
	public void run(){
		for (int i = 0; i < 10; i++){
			System.out.println(phrase);
		}
		timer.cancel();//make sure it doesn't repeat
	}
	
	public static void main(String [] args){
		ThreadExample t1 = new ThreadExample(2, "hello1");//schedules a ThreadExample task to run after 2 seconds
		ThreadExample t2 = new ThreadExample(1, "hello2");
		ThreadExample t3 = new ThreadExample(3, "world1");
		ThreadExample t4 = new ThreadExample(3, "world2");
		
		//note that t3 and t4 run at the same time.... which one will appear first? (they will be inter-mixed because they are both trying to print at the "same time"
	}
}
