Guest User

Untitled

a guest
Nov 19th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. public static class Clock extends Thread {
  2. private int seconds;
  3.  
  4. @Override
  5. public void run() {
  6. try {
  7. while (!currentThread().isInterrupted()) {
  8. Thread.sleep(1000);
  9. seconds++;
  10. System.out.println(seconds);
  11. }
  12. } catch (InterruptedException e) {
  13. System.out.println("Конец отсчета.");
  14. }
  15. }
  16. }
  17.  
  18. public static void main(String[] args) throws InterruptedException {
  19. Clock clock = new Clock();
  20. clock.start();
  21. Thread.sleep(5000);
  22. clock.interrupt();
  23.  
  24. seconds++;
  25. System.out.println(seconds);
Add Comment
Please, Sign In to add comment