java - Thread updating GUI on dispatcher thread causes exception -


I have 2 threads, one thread that runs "server" for my app, and the other is the event dispatcher Displayed for GUI:

  public static zero main (string [] args) {// connection runtime R2 = new Runnabel () {@ Override Public Wide Run () {App. ConnectToServer (); }}; // Launch the main window SwingUtilities.invokeLater (New Runnabal) (Public Zero Run) {// Install Theme WebLink Endfile (); // launches main window; bootwind myMainWindow = new BootWindow ();}}); Thread thread = new thread (R2); Thr2.start (); } // static static app for example getInstance () {if (example == zero) {// window example example = create new app; } Return Example; } // server connection private static zero connect toServer () {System.out.println ("Connecting to e-Trade Manager server .."); ATM server server = new ATM server (); Server.connectEtmServer (); }   

There is a way in the app thread in the app that listens new messages from a new server, then this method calls the update status in a class that is in the GUI thread The background color of a panel tries to update:

The method that is listening:

  @Override Public Zero Process SystemStatus (SystemStatusUpdateWrapper systemUpdate) {System.out.println ("---- System Update ----"); System.out.println ("Connection ID:" + systemUpdate.getConnectionId ()); System.out.println ("System Status:" + systemUpdate.getSystemStatus ()); System.out.println ("Risk State:" + systemUpdate.getRiskState ()); Println ("--------- end ---------"); Summary smryWindow = new summary (); SmryWindow.updateStatus ("Q Time", systemUpdate.getSystemStatus ()); } {/ Code>  

Update method in GUI thread

  public zero update state (string panel name, string status) {if (panelName = "Qt") {if (position == "enabled") {qtimeStatusPanel.setBackground (Color.GREEN); Try {qtimeStatusPanel.validate (); QtimeStatusPanel.repaint (); } Hold (exception before) {System.err.println (ex.getMessage ()); }} And {qtimeStatusPanel.setBackground (Color.RED); }}}   

When an updatestat is called it, it throws an exception:

  java.util.ConcurrentModificationException at java.util.WeakHashMap $ HashIterator .nextEntry (WeakHashMap.java:762) java.util.WeakHashMap $ EntryIterator.next (WeakHashMap.java:801) java.util.WeakHashMap $ EntryIterator.next (WeakHashMap.java:799) com.alee.managers.style .applySkin (StyleManager.java:300) on StylManager   

I'm not sure how to handle it, any advice?

Exclude from the Iterator's own () method, the Iterator will throw a concurrent correction concept . " A ?? Verify that you are using an iterator, as shown.

Your program can also be properly synchronized. You can update the GUI when used, as shown.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -