I\'m trying to creating a test class to open a JFrame. In order to stop the window from closing the moment the main thread finishes I added the code to open up the window in ano
the problem occurs when you try to set a Thread to Daemon(true). When you exit your application the thread cannot be stopped and hence throws an java.lang.IllegalStateException: Shutdown in progress
when you came over this problem you have to explicitly tell the Runtime to close the thread anyway, by adding a shotdownhook.
public void createIntegerClass() throws Exception {
Thread t = new Thread("Test Thread") {...};
Runtime.getRuntime().addShutdownHook(t);//explicit!
t.start();
t.setDaemon(true);
}
The exception message tells you exactly what is wrong: you're trying to create a new thread while the JVM is shutting down.
The reason the JVM shuts down when the main thread finishes is because you call setDaemon(true)
on your event thread. Remove that line and the JVM will stay up as long as that thread is alive.