From: Ian Jackson Date: Sat, 2 Apr 2011 17:57:10 +0000 (+0100) Subject: thread fixes: names for threads, etc. X-Git-Tag: 1.0.5~7 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=jarrg-ian.git;a=commitdiff_plain;h=850693e6c105d13aad069dafb3f57ce315bfe3c0 thread fixes: names for threads, etc. --- diff --git a/src/net/chiark/yarrg/MarketUploader.java b/src/net/chiark/yarrg/MarketUploader.java index 4e78282..7df37f4 100644 --- a/src/net/chiark/yarrg/MarketUploader.java +++ b/src/net/chiark/yarrg/MarketUploader.java @@ -71,6 +71,7 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { private AccessibleContext sidePanel; private HashMap commodMap; public PrintStream dtxt = null; + private int uploadcounter = 0; /* * UTILITY METHODS AND SUBCLASSES @@ -89,7 +90,8 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { private void debuglog(String s) { if (dtxt == null) return; long now = new Date().getTime(); - dtxt.println("progress "+(now - startTime)+"ms "+s); + dtxt.println("progress "+(now - startTime)+"ms " + +Thread.currentThread().getName()+": "+s); } private void debug_write_stringdata(String what, String data) @@ -247,14 +249,14 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { } private void progressNote(final String s_in) throws Exception { - new UIX() { public void body() { + new UIA() { public void body() { String arb = null; arb = arbitrageResult.getText(); String s = s_in; if (arb != null && arb.length() != 0) s = "" + arb + "
" + s; progmon.setNote(s); - }}.exec("progressNote"); + }}.exec("progressNote "+s_in); } /* @@ -351,15 +353,16 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { findMarket.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { on_ui_thread(); + uploadcounter++; findMarket.setEnabled(false); resultSummary.setText(""); arbitrageResult.setText(""); - new Thread() { + new Thread("MarketUploader-uploader-"+uploadcounter) { public void run() { startTime = new Date().getTime(); unknownPCTBcommods = 0; try { - runUpload(); + runUpload(uploadcounter); } catch(Exception e) { error(e.toString()); e.printStackTrace(); @@ -405,6 +408,20 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { * error and error_html may be called from any thread */ + private abstract class UIA implements Runnable { + private String what; + public abstract void body(); + public void run() { + debuglog("UIA 2 "+what+" begin"); + body(); + debuglog("UIA 3 "+what+" done"); + } + public void exec(String what_in) { + what = what_in; + debuglog("UIA 1 "+what+" request"); + EventQueue.invokeLater(this); + } + }; private abstract class UIXR implements Runnable { public abstract ReturnType bodyr(); public ReturnType return_value; @@ -413,7 +430,7 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { 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()) { @@ -426,7 +443,7 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { debuglog("UIX 4 "+what+" (other thread) exit"); } return return_value; - }; + } }; private abstract class UIX extends UIXR implements Runnable { public abstract void body(); @@ -469,9 +486,9 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { } private void setProgress(final int nv) throws Exception { - new UIX() { public void body() { + new UIA() { public void body() { progmon.setProgress(nv); - }}.exec("setProgress"); + }}.exec("setProgress "+nv); } private boolean isCanceled() throws Exception { return new UIXR() { public Boolean bodyr() { @@ -574,6 +591,9 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { * @exception Exception if an error we didn't expect occured */ private class YarrgTimestampFetcher extends Thread { + public YarrgTimestampFetcher(int counter) { + super("MarketUploader-YarrgTimestampFetcher-"+uploadcounter); + } public String ts = null; public void run() { try { @@ -585,7 +605,7 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { } }; - private void runUpload() throws Exception { + private void runUpload(int counter) throws Exception { on_our_thread(); boolean doneyarrg = false, donepctb = false; @@ -595,7 +615,7 @@ implements Runnable, TopLevelWindowListener, GUIInitializedListener { if (uploadToYarrg) { debuglog("(async) yarrg timestamp..."); - yarrgts_thread = new YarrgTimestampFetcher(); + yarrgts_thread = new YarrgTimestampFetcher(counter); yarrgts_thread.start(); }