{"id":1704,"date":"2015-08-17T21:10:13","date_gmt":"2015-08-17T19:10:13","guid":{"rendered":"https:\/\/bob-team.de\/wordpress\/?p=1704"},"modified":"2017-06-07T16:04:35","modified_gmt":"2017-06-07T14:04:35","slug":"swingworker-und-event-dispatch-thread-edt","status":"publish","type":"post","link":"https:\/\/bob-team.de\/wordpress\/2015\/08\/17\/swingworker-und-event-dispatch-thread-edt\/","title":{"rendered":"SwingWorker und Event Dispatch Thread (EDT)"},"content":{"rendered":"<pre lang=\"java\">System.out.println(\"TID=\" + \r\n      Thread.currentThread().getId() + \" (main)\");\r\nfinal SwingWorker<String, String> x = \r\n      new SwingWorker<String, String>() {\r\n   @Override\r\n   protected String doInBackground() throws Exception {\r\n      final long tid = Thread.currentThread().getId();\r\n      System.out.println(\"TID=\" + tid + \r\n            \" doInBackground() isEventDispatchThread=\" +\r\n            SwingUtilities.isEventDispatchThread());\r\n      System.out.println(\"Long running code goes here.\");\r\n      return \"\";\r\n   }\r\n   @Override\r\n   protected void done() {\r\n      final long tid = Thread.currentThread().getId();\r\n      System.out.println(\"TID=\" + tid + \r\n            \"          done() isEventDispatchThread=\" +\r\n            SwingUtilities.isEventDispatchThread());\r\n      System.out.println(\"GUI updates\/changes go here.\");\r\n   }\r\n};\r\nx.execute();<\/pre>\n<pre lang=\"java\">TID=1 (main)\r\nTID=9 doInBackground() isEventDispatchThread=false\r\nLong running code goes here.\r\nTID=16          done() isEventDispatchThread=true\r\nGUI updates\/changes go here.<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>System.out.println(&#8222;TID=&#8220; + Thread.currentThread().getId() + &#8220; (main)&#8220;); final SwingWorker x = new SwingWorker() { @Override protected String doInBackground() throws Exception { final long tid = Thread.currentThread().getId(); System.out.println(&#8222;TID=&#8220; + tid + &#8220; doInBackground() isEventDispatchThread=&#8220; + SwingUtilities.isEventDispatchThread()); System.out.println(&#8222;Long running code goes here.&#8220;); return &#8222;&#8220;; } @Override protected void done() { final long tid = Thread.currentThread().getId(); System.out.println(&#8222;TID=&#8220; + tid [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1704","post","type-post","status-publish","format-standard","hentry","category-java","entry"],"_links":{"self":[{"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/posts\/1704","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/comments?post=1704"}],"version-history":[{"count":4,"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/posts\/1704\/revisions"}],"predecessor-version":[{"id":1943,"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/posts\/1704\/revisions\/1943"}],"wp:attachment":[{"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/media?parent=1704"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/categories?post=1704"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bob-team.de\/wordpress\/wp-json\/wp\/v2\/tags?post=1704"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}