From 56a013ad992b3c8463ce43d7f73d724bb16448f5 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 2 Apr 2011 18:34:32 +0100 Subject: [PATCH] thread fixes: debugging from UIX --- src/net/chiark/yarrg/MarketUploader.java | 30 ++++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/net/chiark/yarrg/MarketUploader.java b/src/net/chiark/yarrg/MarketUploader.java index 4f50228..4e78282 100644 --- a/src/net/chiark/yarrg/MarketUploader.java +++ b/src/net/chiark/yarrg/MarketUploader.java @@ -254,7 +254,7 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { if (arb != null && arb.length() != 0) s = "" + arb + "
" + s; progmon.setNote(s); - }}.exec(); + }}.exec("progressNote"); } /* @@ -374,7 +374,7 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { progmon = null; } findMarket.setEnabled(true); - }}.exec(); + }}.exec("tidying"); } catch (Exception e) { System.err.println("exception tidying on UI thread:"); e.printStackTrace(); @@ -408,12 +408,22 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { private abstract class UIXR implements Runnable { public abstract ReturnType bodyr(); public ReturnType return_value; - public void run() { return_value = bodyr(); }; - public ReturnType exec() throws Exception { + private String what; + public void run() { + debuglog("UIX 2 "+what+" begin"); + return_value = bodyr(); + debuglog("UIX 3 "+what+" done"); + }; + public ReturnType exec(String what_in) throws Exception { + what = what_in; if (EventQueue.isDispatchThread()) { + debuglog("UIX 1 "+what+" (event thread) entry"); this.run(); + debuglog("UIX 4 "+what+" (event thread) exit"); } else { + debuglog("UIX 1 "+what+" (other thread) entry"); EventQueue.invokeAndWait(this); + debuglog("UIX 4 "+what+" (other thread) exit"); } return return_value; }; @@ -432,7 +442,7 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { resultSummary.setText("failed"); JOptionPane.showMessageDialog(frame,msg,"Error", JOptionPane.ERROR_MESSAGE); - }}.exec(); + }}.exec("error()"); } catch (Exception e) { System.err.println("exception reporting to UI thread:"); e.printStackTrace(); @@ -461,12 +471,12 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { private void setProgress(final int nv) throws Exception { new UIX() { public void body() { progmon.setProgress(nv); - }}.exec(); + }}.exec("setProgress"); } private boolean isCanceled() throws Exception { return new UIXR() { public Boolean bodyr() { return new Boolean(progmon.isCanceled()); - }}.exec().booleanValue(); + }}.exec("isCanceled").booleanValue(); } /* @@ -618,7 +628,7 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { debuglog("getocean done"); return at; - }}.exec(); + }}.exec("accesstable"); if (accesstable == null) return; if (latch != null) { @@ -673,7 +683,7 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { debuglog("table read..."); return getData(accesstable); - }}.exec(); + }}.exec("data"); if (data == null) return; if (showArbitrage) { @@ -784,7 +794,7 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { final String summary_final = summary; new UIX() { public void body() { resultSummary.setText(summary_final); - }}.exec(); + }}.exec("resultSummary.setText"); debuglog("done."); } -- 2.30.2