откуда run() знает что надо запускаться, если в start(String threadName) мы запускаем thread.start() который переменная класса, но нигде не запускается сам TaskManipulator ?
как это вообще работает?
public static void main(String[] args) throws InterruptedException {
CustomThreadManipulator manipulator = new TaskManipulator();
manipulator.start("first");
Thread.sleep(150);
manipulator.stop();
}
public class TaskManipulator implements Runnable, CustomThreadManipulator {
Thread thread;
@Override
public void run() {
Thread thread = Thread.currentThread();
while (!thread.isInterrupted()) {
System.out.println(thread.getName());
try {
Thread.sleep(100);
} catch (InterruptedException e) {
break;
}
}
}
@Override
public void start(String threadName) {
thread = new Thread(this, threadName);
thread.start();
}