@Override
public void run() {
System.out.println(thread.getName());
while (!thread.isInterrupted()) {
try {
Thread.sleep(100);
System.out.println(thread.getName());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
@Override
public void start(String threadName) {
thread = new Thread(this);
thread.setName(threadName);
thread.start();
}
@Override
public void stop() {
thread.interrupt();
}
}
1. зачем мы в блоке catch прерываем основную нить?
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
2. Зачем в параметре при создании потока передается объект this
thread = new Thread(this);