Am getting the below exception thrown multiple times after my shutdown hook has completed. The class Settings is entirely static and the hook is to ensure it's save() method is called on program exit, usually via the gui close button. The save is very short and does complete. When debugging the exception is only raised after the run method completes and the threads exit method terminates.
Is this the best method to ensure save is called and if so what is going wrong?
Thanks
Exception while removing reference: java.util.concurrent.RejectedExecutionException
java.util.concurrent.RejectedExecutionException
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:1759)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:767)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:658)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:92)
at sun.awt.shell.Win32ShellFolder2$ComTask.execute(Win32ShellFolder2.java:1214)
at sun.awt.shell.Win32ShellFolder2$FolderDisposer.dispose(Win32ShellFolder2.java:170)
at sun.java2d.Disposer.run(Disposer.java:128)
at java.lang.Thread.run(Thread.java:619)
// ensure save on exit
Runtime.getRuntime().addShutdownHook(new Thread("SettingsSaver") {
public void run() {
try {
Settings.save();
} catch (SettingsException e) {
JOptionPane.showMessageDialog(null, e.getMessage(),
"Error Saving Settings",
JOptionPane.WARNING_MESSAGE);
}
}
});