From 0c345d155988fe6e87fa6c125d52b472791c4fea Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Mon, 2 Jul 2012 09:51:43 +0200 Subject: [PATCH] giving threads name so its easier to see whats happening during debugging and within a thread dump --- source/de/anomic/crawler/Cache.java | 3 +- source/de/anomic/crawler/CrawlStacker.java | 2 + source/net/yacy/cora/protocol/Domains.java | 1 + .../net/yacy/cora/protocol/ftp/FTPClient.java | 8 +++- .../federated/opensearch/SRURSSConnector.java | 1 + source/net/yacy/cora/storage/Files.java | 10 +++-- .../yacy/document/content/dao/PhpBB3Dao.java | 1 + .../net/yacy/document/parser/pdfParser.java | 1 + source/net/yacy/gui/YaCyApp.java | 37 ++++++++++--------- source/net/yacy/kelondro/blob/MapHeap.java | 1 + .../kelondro/data/word/WordReferenceRow.java | 1 + .../net/yacy/kelondro/table/SplitTable.java | 1 + source/net/yacy/search/Switchboard.java | 13 +++++-- source/net/yacy/search/query/SearchEvent.java | 2 + 14 files changed, 55 insertions(+), 27 deletions(-) diff --git a/source/de/anomic/crawler/Cache.java b/source/de/anomic/crawler/Cache.java index d027eb8ab..6afd3f659 100644 --- a/source/de/anomic/crawler/Cache.java +++ b/source/de/anomic/crawler/Cache.java @@ -103,6 +103,7 @@ public final class Cache { Thread startupCleanup = new Thread() { @Override public void run() { + Thread.currentThread().setName("Cache startupCleanup"); // enumerate the responseHeaderDB and find out all entries that are not inside the fileDBunbuffered BlockingQueue q = responseHeaderDB.keyQueue(1000); final HandleSet delkeys = new HandleSet(Word.commonHashLength, Base64Order.enhancedCoder, 1); @@ -146,7 +147,7 @@ public final class Cache { public static void commit() { fileDB.flushAll(); } - + /** * clear the cache */ diff --git a/source/de/anomic/crawler/CrawlStacker.java b/source/de/anomic/crawler/CrawlStacker.java index 35d1a3f11..388ff1d35 100644 --- a/source/de/anomic/crawler/CrawlStacker.java +++ b/source/de/anomic/crawler/CrawlStacker.java @@ -185,6 +185,7 @@ public final class CrawlStacker { new Thread() { @Override public void run() { + Thread.currentThread().setName("enqueueEntriesAsynchronous"); enqueueEntries(initiator, profileHandle, hyperlinks, true); } }.start(); @@ -240,6 +241,7 @@ public final class CrawlStacker { new Thread() { @Override public void run() { + Thread.currentThread().setName("enqueueEntriesFTP"); BlockingQueue queue; try { queue = FTPClient.sitelist(host, port); diff --git a/source/net/yacy/cora/protocol/Domains.java b/source/net/yacy/cora/protocol/Domains.java index bc92499ff..9531d0dd4 100644 --- a/source/net/yacy/cora/protocol/Domains.java +++ b/source/net/yacy/cora/protocol/Domains.java @@ -746,6 +746,7 @@ public class Domains { new Thread() { @Override public void run() { + Thread.currentThread().setName("Domains: init"); // try to get local addresses from interfaces try { final Enumeration nis = NetworkInterface.getNetworkInterfaces(); diff --git a/source/net/yacy/cora/protocol/ftp/FTPClient.java b/source/net/yacy/cora/protocol/ftp/FTPClient.java index 8c7bdb1c8..12fc239f5 100644 --- a/source/net/yacy/cora/protocol/ftp/FTPClient.java +++ b/source/net/yacy/cora/protocol/ftp/FTPClient.java @@ -237,6 +237,7 @@ public class FTPClient { super(); } + @Override public synchronized Class loadClass(final String classname, final boolean resolve) throws ClassNotFoundException { Class c = findLoadedClass(classname); if (c == null) { @@ -945,8 +946,8 @@ public class FTPClient { return true; } final String[] name = this.currentLocalPath.list(); - for (int n = 0; n < name.length; ++n) { - log.info(ls(new File(this.currentLocalPath, name[n]))); + for (String element : name) { + log.info(ls(new File(this.currentLocalPath, element))); } return true; } @@ -2539,6 +2540,7 @@ public class FTPClient { @Override public void run() { try { + Thread.currentThread().setName("FTP.sitelist(" + host + ":" + port + ")"); sitelist(ftpClient, "/", queue); ftpClient.quit(); } catch (final Exception e) {} finally { @@ -2757,8 +2759,10 @@ public class FTPClient { this.password = p; } + @Override public final void run() { try { + Thread.currentThread().setName("FTP.pt(" + this.host + ")"); put(this.host, this.localFile, this.remotePath, this.remoteName, this.account, this.password); } catch (final IOException e) { log.error(e, e); diff --git a/source/net/yacy/cora/services/federated/opensearch/SRURSSConnector.java b/source/net/yacy/cora/services/federated/opensearch/SRURSSConnector.java index 52ce78039..ad80a02b2 100644 --- a/source/net/yacy/cora/services/federated/opensearch/SRURSSConnector.java +++ b/source/net/yacy/cora/services/federated/opensearch/SRURSSConnector.java @@ -130,6 +130,7 @@ public class SRURSSConnector extends Thread implements SearchAccumulator { final Thread job = new Thread() { @Override public void run() { + Thread.currentThread().setName("searchSRURSS:" + urlBase); int startRecord = 0; RSSMessage message; int maximumRecords = maximumRecordsInit; diff --git a/source/net/yacy/cora/storage/Files.java b/source/net/yacy/cora/storage/Files.java index 017b6fe6a..61959dc5f 100644 --- a/source/net/yacy/cora/storage/Files.java +++ b/source/net/yacy/cora/storage/Files.java @@ -55,10 +55,10 @@ public class Files { InputStream is = new BufferedInputStream(new FileInputStream(f)); if (f.toString().endsWith(".bz2")) is = new BZip2CompressorInputStream(is); if (f.toString().endsWith(".gz")) is = new GZIPInputStream(is); - + return is; } - + /** * reading a file line by line should be done with two concurrent processes * - one reading the file and doing IO operations @@ -80,7 +80,9 @@ public class Files { final InputStream is = read(f); final BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8")); Thread t = new Thread() { - public void run() { + @Override + public void run() { + Thread.currentThread().setName("Files.concurrentLineReader:" + f); String line; try { while ((line = br.readLine()) != null) { @@ -111,7 +113,7 @@ public class Files { t.start(); return q; } - + /** * copy a file or a complete directory * @param from the source file or directory diff --git a/source/net/yacy/document/content/dao/PhpBB3Dao.java b/source/net/yacy/document/content/dao/PhpBB3Dao.java index 486f23962..41e3a22db 100644 --- a/source/net/yacy/document/content/dao/PhpBB3Dao.java +++ b/source/net/yacy/document/content/dao/PhpBB3Dao.java @@ -179,6 +179,7 @@ public class PhpBB3Dao implements Dao { Thread dbreader = new Thread() { @Override public void run() { + Thread.currentThread().setName("PhpBB3Dao.toQueue"); Statement stmt = null; ResultSet rs = null; try { diff --git a/source/net/yacy/document/parser/pdfParser.java b/source/net/yacy/document/parser/pdfParser.java index 0f9381202..e2b6472dc 100644 --- a/source/net/yacy/document/parser/pdfParser.java +++ b/source/net/yacy/document/parser/pdfParser.java @@ -142,6 +142,7 @@ public class pdfParser extends AbstractParser implements Parser { final Thread t = new Thread() { @Override public void run() { + Thread.currentThread().setName("pdfParser.getText:" + location); try { writer.append(stripper.getText(pdfDoc)); } catch (final Throwable e) {} diff --git a/source/net/yacy/gui/YaCyApp.java b/source/net/yacy/gui/YaCyApp.java index 7230836b4..924f96683 100644 --- a/source/net/yacy/gui/YaCyApp.java +++ b/source/net/yacy/gui/YaCyApp.java @@ -2,7 +2,7 @@ * YaCyApp * Copyright 2010 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany * First released 05.08.2010 at http://yacy.net - * + * * $LastChangedDate$ * $LastChangedRevision$ * $LastChangedBy$ @@ -11,12 +11,12 @@ * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with this program in the file lgpl21.txt * If not, see . @@ -48,7 +48,7 @@ import net.yacy.gui.framework.Switchboard; import org.apache.log4j.Logger; public class YaCyApp { - + public static Logger log = Logger.getLogger(YaCyApp.class); private static JFrame app; private static Operation operation; @@ -70,33 +70,34 @@ public class YaCyApp { public splashCanvas(ImageObserver obs) { this.obs = obs; } @Override public void paint(Graphics g) { - if (splashImg != null) g.drawImage(splashImg, 0, 0, obs); + if (splashImg != null) g.drawImage(splashImg, 0, 0, this.obs); } } - + public static class Op implements Operation { - + JFrame app; final String host; final int port; - + public Op(JFrame app, String host, int port) { this.app = app; this.host = host; this.port = port; } - + + @Override public void closeAndExit() { - if (app != null) app.setVisible(false); // fake closing + if (this.app != null) this.app.setVisible(false); // fake closing //Browser.openBrowser("http://" + host + ":" + port + "/Steering.html?shutdown="); net.yacy.search.Switchboard.getSwitchboard().terminate(10, "shutdown request from gui"); Switchboard.shutdown(); //System.exit(0); } } - + public static void start(String host, int port) { - + Switchboard.startInfoUpdater(); operation = new Op(app, host, port); @@ -108,6 +109,7 @@ public class YaCyApp { OpenItem.setEnabled(false); JMenuItem QuitItem = new JMenuItem("Quit"); QuitItem.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { operation.closeAndExit(); } @@ -115,7 +117,7 @@ public class YaCyApp { FileMenu.add(OpenItem); FileMenu.add(QuitItem); menues.add(FileMenu); - + // the edit menu JMenu EditMenu = new JMenu("Edit"); JMenuItem CutItem = new JMenuItem("Cut"); @@ -128,12 +130,13 @@ public class YaCyApp { EditMenu.add(CopyItem); EditMenu.add(PasteItem); menues.add(EditMenu); - + // registering shutdown hook log.info("Registering Shutdown Hook"); Thread t = new Thread() { @Override public void run() { + Thread.currentThread().setName("YaCyApp"); app = new Application("YaCy GUI", operation, menues, new InfoPage("localhost", 8090)); app.setLocationRelativeTo(null); app.setVisible(true); @@ -142,12 +145,12 @@ public class YaCyApp { Switchboard.addShutdownHook(t, net.yacy.yacy.shutdownSemaphore); SwingUtilities.invokeLater(t); } - + public static void main(String[] args) { - + if (args.length > 0) Switchboard.load(new File(args[0])); start("localhost", 8090); - + } } \ No newline at end of file diff --git a/source/net/yacy/kelondro/blob/MapHeap.java b/source/net/yacy/kelondro/blob/MapHeap.java index fadc160b3..54f331156 100644 --- a/source/net/yacy/kelondro/blob/MapHeap.java +++ b/source/net/yacy/kelondro/blob/MapHeap.java @@ -525,6 +525,7 @@ public class MapHeap implements Map> { (new Thread() { @Override public void run() { + Thread.currentThread().setName("MapHeap.keyQueue:" + size); try { final Iterator i = MapHeap.this.blob.keys(true, false); while (i.hasNext()) diff --git a/source/net/yacy/kelondro/data/word/WordReferenceRow.java b/source/net/yacy/kelondro/data/word/WordReferenceRow.java index 472421b2d..7bc43b1ff 100644 --- a/source/net/yacy/kelondro/data/word/WordReferenceRow.java +++ b/source/net/yacy/kelondro/data/word/WordReferenceRow.java @@ -217,6 +217,7 @@ public final class WordReferenceRow extends AbstractReference implements WordRef this.worker[i] = new Thread() { @Override public void run() { + Thread.currentThread().setName("WordReferenceRow.ExternalParser:" + concurrency); String s; try { while ((s = ExternalParser.this.in.take()) != PIN) { diff --git a/source/net/yacy/kelondro/table/SplitTable.java b/source/net/yacy/kelondro/table/SplitTable.java index c86eccb43..9400b627a 100644 --- a/source/net/yacy/kelondro/table/SplitTable.java +++ b/source/net/yacy/kelondro/table/SplitTable.java @@ -227,6 +227,7 @@ public class SplitTable implements Index, Iterable { final Thread p = new Thread() { @Override public void run() { + Thread.currentThread().setName("SplitTable.warmUp"); a.warmUp(); } }; diff --git a/source/net/yacy/search/Switchboard.java b/source/net/yacy/search/Switchboard.java index 0167a2e38..38bdf9aa0 100644 --- a/source/net/yacy/search/Switchboard.java +++ b/source/net/yacy/search/Switchboard.java @@ -339,6 +339,7 @@ public final class Switchboard extends serverSwitch new Thread() { @Override public void run() { + Thread.currentThread().setName("LibraryProvider.initialize"); LibraryProvider.initialize(Switchboard.this.dictionariesPath); } }.start(); @@ -662,6 +663,7 @@ public final class Switchboard extends serverSwitch new Thread() { @Override public void run() { + Thread.currentThread().setName("Switchboard.initBookmarks"); try { initBookmarks(); } catch ( final IOException e ) { @@ -1157,8 +1159,8 @@ public final class Switchboard extends serverSwitch final int wordCacheMaxCount = (int) getConfigLong(SwitchboardConstants.WORDCACHE_MAX_COUNT, 20000); final long fileSizeMax = - (OS.isWindows) ? sb.getConfigLong("filesize.max.win", (long) Integer.MAX_VALUE) : sb - .getConfigLong("filesize.max.other", (long) Integer.MAX_VALUE); + (OS.isWindows) ? sb.getConfigLong("filesize.max.win", Integer.MAX_VALUE) : sb + .getConfigLong("filesize.max.other", Integer.MAX_VALUE); final int redundancy = (int) sb.getConfigLong("network.unit.dhtredundancy.senior", 1); final int partitionExponent = (int) sb.getConfigLong("network.unit.dht.partitionExponent", 0); final String networkName = getConfig(SwitchboardConstants.NETWORK_NAME, ""); @@ -2727,9 +2729,10 @@ public final class Switchboard extends serverSwitch final Request request = this.loader.request(url, true, true); final CrawlProfile profile = sb.crawler.getActive(ASCII.getBytes(request.profileHandle())); final String acceptedError = this.crawlStacker.checkAcceptance(url, profile, 0); + final String urls = url.toNormalform(false, false); if ( acceptedError != null ) { this.log.logWarning("addToIndex: cannot load " - + url.toNormalform(false, false) + + urls + ": " + acceptedError); return; @@ -2737,6 +2740,7 @@ public final class Switchboard extends serverSwitch new Thread() { @Override public void run() { + Thread.currentThread().setName("Switchboard.addToIndex:" + urls); try { final Response response = Switchboard.this.loader.load(request, CacheStrategy.IFFRESH, true); @@ -2795,6 +2799,7 @@ public final class Switchboard extends serverSwitch this.reference = reference; } + @Override public void run() { final long t = System.currentTimeMillis(); final Map response = @@ -3109,6 +3114,7 @@ public final class Switchboard extends serverSwitch new Thread() { @Override public void run() { + Thread.currentThread().setName("Switchboard.heuristicSite:" + host); String r = host; if ( r.indexOf("//", 0) < 0 ) { r = "http://" + r; @@ -3161,6 +3167,7 @@ public final class Switchboard extends serverSwitch public void run() { QueryParams query = searchEvent.getQuery(); String queryString = query.queryString(true); + Thread.currentThread().setName("Switchboard.heuristicRSS:" + queryString); final int meta = queryString.indexOf("heuristic:", 0); if ( meta >= 0 ) { final int q = queryString.indexOf(' ', meta); diff --git a/source/net/yacy/search/query/SearchEvent.java b/source/net/yacy/search/query/SearchEvent.java index dc5e76723..39fe53b86 100644 --- a/source/net/yacy/search/query/SearchEvent.java +++ b/source/net/yacy/search/query/SearchEvent.java @@ -163,6 +163,7 @@ public final class SearchEvent new Thread() { @Override public void run() { + Thread.currentThread().setName("SearchEvent.primaryRemoteSearches"); RemoteSearch.primaryRemoteSearches( SearchEvent.this.primarySearchThreadsL, QueryParams.hashSet2hashString(SearchEvent.this.query.queryHashes), @@ -553,6 +554,7 @@ public final class SearchEvent new Thread() { @Override public void run() { + Thread.currentThread().setName("SearchEvent.paddAbstract:" + wordhash); for ( final Map.Entry oneref : singleAbstract.entrySet() ) { final String urlhash = oneref.getKey(); final StringBuilder peerlistNew = oneref.getValue();