Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class Clock extends Thread {
- private int seconds;
- @Override
- public void run() {
- try {
- while (!currentThread().isInterrupted()) {
- Thread.sleep(1000);
- seconds++;
- System.out.println(seconds);
- }
- } catch (InterruptedException e) {
- System.out.println("Конец отсчета.");
- }
- }
- }
- public static void main(String[] args) throws InterruptedException {
- Clock clock = new Clock();
- clock.start();
- Thread.sleep(5000);
- clock.interrupt();
- seconds++;
- System.out.println(seconds);
Add Comment
Please, Sign In to add comment