The class CounterThread extends Thread and overrides the run method. The method increments the counter variable in a loop. As it is now, the loop works infinitely. You should fix it by adding interruption handling.
If another thread interrupts this thread, it must print "It was interrupted" and stop.
Please, do not remove the loop. Otherwise, your solution may not pass tests.
Interruptions
Handling interruptions
Report a typo
Write a program in Java 17
class CounterThread extends Thread {
@Override
public void run() {
long counter = 0;
while (true) {
counter++;
}
}
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.