I am developing a Java application and I am at the phase of writing the GUI code. For some reason I am getting crashes on the app with crash reports (not just errors on netbeans console). I wonder if there are problems with the way I am handling events as the report often says AWT dispatch thread crashed.
Should I be creating a new thread to handle the different events
firing from GUI ?
For example by making use of :
Executors.newCachedThreadPool().execute(new Runnable() {
public void run() {}});
Is it possible that something like that fix the crashes? Would it have negative impact on application performance ?
You are probably accessing Swing from multiple threads. Neither AWT nor Swing are thread safe. Consider using the
SwingWorkerclass in order to ensure that it is not accessed outside of the Event Dispatch Thread.For more information, here’s another answer I have given about
SwingWorker.