Figure 12: A utility method to suspend the thread when requested

private synchronized void checkIfSuspended() {
    if (suspended) {
        try {
            wait(); // suspends the thread
        } catch (InterruptedException e) {
            System.out.println(e.toString());
        }
    }
}