I have a while ( true ) loop that should run for the duration of the program. If it is interrupted or terminates, the program should also terminate.In that loop, I occasionally call Thread.sleep () to avoid monopolizing the CPU. When I sleep, I have to catch an InterruptedException.When this exception happens, how should I proceed? Some choices I have thought of are:Log the exception and continue looping. Terminate the program.Log the exception and continue, but if it happens more than N times, then terminate. Even after reading a bit about the topic, I'm not really sure what an InterruptedException represents if it arises here. My program certainly won't generate it, so it would have to come from the OS or from the JVM. What do you think this is a good way to handle this InterruptedException?public class LibraryUpdater {    private boolean runLaterPending = false;    public LibraryUpdater( ) {        Thread libraryUpdaterThread = new Thread( () -> {            while ( true ) {                if( !runLaterPending ) {                    updateLibrary();                }                try {                    Thread.sleep ( 100 );                } catch ( InterruptedException e ) {                    //TODO: Handle this properly                }            }        });        libraryUpdaterThread.setDaemon( true );        libraryUpdaterThread.start();    }    private void updateLibrary () {         if ( updatePending ){            runLaterPending = true;            Platform.runLater( () -> {                //Do time-consuming update            });            runLaterPending = false;        }    }}
Continue or Terminate after catching Interrupted Exception?
java;error handling