Program.java 646 B

1234567891011121314151617181920212223242526272829303132
  1. import weather.*;
  2. import java.lang.Thread;
  3. import java.util.Timer;
  4. import java.util.TimerTask;
  5. public class Program {
  6. public static void main(String[] args) {
  7. Central central = new Central();
  8. String[] locations = { "vienna", "moscow", "tokyo", "bangkok", "kapstadt" };
  9. for (String location: locations) {
  10. central.addStation(location);
  11. }
  12. (new Timer()).scheduleAtFixedRate(new TimerTask() {
  13. long t0 = System.currentTimeMillis();
  14. @Override
  15. public void run() {
  16. if (System.currentTimeMillis() - t0 > 20 * 1000) {
  17. cancel();
  18. } else {
  19. central.measurementEvent();
  20. }
  21. }
  22. }, 0, 1000 * 5);
  23. }
  24. }