package threadtrial;

import java.io.IOException;
import java.util.*;

/**
 * @author Daniel "3ICE" Berezvai
 */
public class ThreadTrial {

public static void main(String[] args) throws IOException, InterruptedException {
  List<MySampleThread> threads = new ArrayList<>();
  List<Timer> timers = new ArrayList<>();
  threads.add(new MySampleThread());
  threads.add(new MySampleThread());
  threads.add(new MySampleThread());
  for (MySampleThread mySampleThread : threads) {
    Timer timer = new Timer();
    timer.schedule(mySampleThread, 0, 40);
    timers.add(timer);
  }
  Thread.sleep(1_500);
  for (Timer timer : timers) {
    timer.cancel();
  }
}

private static class MySampleThread extends TimerTask {

public void run() {
  System.out.println("Thread #" + Thread.currentThread().getId() + "; ");
  try {
    Thread.sleep(100);
  } catch (InterruptedException ex) {
  }
}
}
}
