It was interrupted

Report a typo

Here's a class Worker that extends Thread.

class Worker extends Thread {
    
    @Override
    public void run() {
        String msg = "It was interrupted";     // 1
        
        try {
            Thread.sleep(200);                 // 2
        } catch (InterruptedException e) {
            System.out.println(msg);
        }
        
        int i = 0;                             // 3
        while (i < 100_000) {
            if (isInterrupted()) {
                System.out.println(msg);
                return;
            }                      
            i++;                               // 4
        }
        
        System.out.println("Finished");        // 5
    }
}

Another thread calls the interrupt method of this thread. The Worker thread will print "It was interrupted" if another thread interrupts it during...

Select one or more options from the list
___

Create a free account to access the full topic