attaching names to all Threads to get a better view in profiling tools

like VisualVM
This commit is contained in:
Michael Peter Christen 2014-02-28 15:02:01 +01:00
parent fdaeac374a
commit 6ed9c0164e
19 changed files with 30 additions and 5 deletions

View File

@ -147,6 +147,7 @@ public abstract class AbstractSolrConnector implements SolrConnector {
final Thread t = new Thread() {
@Override
public void run() {
this.setName("AbstractSolrConnector:concurrentDocumentsByQuery(" + querystring + ")");
int o = offset;
int count = 0;
while (System.currentTimeMillis() < endtime && count < maxcount) {
@ -178,6 +179,7 @@ public abstract class AbstractSolrConnector implements SolrConnector {
final Thread t = new Thread() {
@Override
public void run() {
this.setName("AbstractSolrConnector:concurrentIDsByQuery(" + querystring + ")");
int o = offset;
while (System.currentTimeMillis() < endtime) {
try {

View File

@ -58,9 +58,10 @@ public class ConcurrentUpdateSolrConnector implements SolrConnector {
private final static Object POISON_PROCESS = new Object();
private class ProcessHandler implements Runnable {
private class ProcessHandler extends Thread {
@Override
public void run() {
try {
Object process;
Collection<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
@ -114,7 +115,7 @@ public class ConcurrentUpdateSolrConnector implements SolrConnector {
private ARC<String, Metadata> metadataCache;
private ARH<String> missCache;
private BlockingQueue<Object> processQueue;
private Thread processHandler;
private ProcessHandler processHandler;
public ConcurrentUpdateSolrConnector(final SolrConnector connector, final int updateCapacity, final int idCacheCapacity, final int concurrency) {
this.connector = connector;
@ -200,7 +201,7 @@ public class ConcurrentUpdateSolrConnector implements SolrConnector {
public void ensureAliveProcessHandler() {
if (this.processHandler == null || !this.processHandler.isAlive()) {
this.processHandler = new Thread(new ProcessHandler());
this.processHandler = new ProcessHandler();
this.processHandler.setName(this.getClass().getName() + "_ProcessHandler");
this.processHandler.start();
}

View File

@ -423,6 +423,7 @@ public class EmbeddedSolrConnector extends SolrServerConnector implements SolrCo
final Thread t = new Thread() {
@Override
public void run() {
this.setName("EmbeddedSolrConnector.concurrentIDsByQuery(" + querystring + ")");
int o = offset, responseCount = 0;
DocListSearcher docListSearcher = null;
while (System.currentTimeMillis() < endtime) {

View File

@ -347,6 +347,7 @@ public class MirrorSolrConnector extends AbstractSolrConnector implements SolrCo
Thread t0 = new Thread() {
@Override
public void run() {
this.setName("MirrorSolrConnector.getCountByQuery/t0");
try {
count.addAndGet(MirrorSolrConnector.this.solr0.getCountByQuery(querystring));
} catch (final IOException e) {}
@ -356,6 +357,7 @@ public class MirrorSolrConnector extends AbstractSolrConnector implements SolrCo
Thread t1 = new Thread() {
@Override
public void run() {
this.setName("MirrorSolrConnector.getCountByQuery/t1");
try {
count.addAndGet(MirrorSolrConnector.this.solr1.getCountByQuery(querystring));
} catch (final IOException e) {}

View File

@ -365,6 +365,7 @@ public class ServerShard extends SolrServer {
Thread t0 = new Thread() {
@Override
public void run() {
this.setName("ServerShard.query/1(" + params.toString() + ")");
QueryResponse rsp;
try {
rsp = s.query(params);
@ -397,6 +398,7 @@ public class ServerShard extends SolrServer {
Thread t0 = new Thread() {
@Override
public void run() {
this.setName("ServerShard.query/2(" + params.toString() + ")");
QueryResponse rsp;
try {
rsp = s.query(params, method);

View File

@ -691,6 +691,7 @@ public class HTTPClient {
final Throwable[] te = new Throwable[]{null};
Thread t = new Thread() {
public void run() {
this.setName("HTTPClient.execute(" + httpUriRequest.getURI() + ")");
try {
thr[0] = client.execute(httpUriRequest, context);
} catch (Throwable e) {
@ -883,6 +884,7 @@ public class HTTPClient {
public IdleConnectionMonitorThread(HttpClientConnectionManager connMgr) {
super();
this.setName("HTTPClient.IdleConnectionMonitorThread");
this.connMgr = connMgr;
}

View File

@ -64,6 +64,7 @@ public class Array {
private static class SortJobWorker extends Thread {
public void run() {
this.setName("Array.SortJobWorker");
SortJob<?> job;
try {
while ((job = sortJobs.take()) != POISON_JOB_WORKER) {

View File

@ -627,6 +627,7 @@ public class CrawlQueues {
this.code = Integer.valueOf(entry.hashCode());
this.setPriority(Thread.MIN_PRIORITY); // http requests from the crawler should not cause that other functions work worse
this.profile = CrawlQueues.this.sb.crawler.get(UTF8.getBytes(this.request.profileHandle()));
this.setName("CrawlQueues.Loader(" + entry.url() + ")");
}
private long age() {

View File

@ -200,6 +200,7 @@ public class RobotsTxt {
if (robotsTable == null || robotsTable.containsKey(robotsTable.encodedKey(urlHostPort))) return;
Thread t = new Thread() {
public void run(){
this.setName("Robots.txt:ensureExist(" + theURL.toNormalform(true) + ")");
// make or get a synchronization object
DomSync syncObj = RobotsTxt.this.syncObjects.get(urlHostPort);
if (syncObj == null) {

View File

@ -272,6 +272,7 @@ public class Jetty8HttpServerImpl implements YaCyHttpServer {
@Override
public void run() {
this.setName("Jetty8HttpServer.reconnect");
try {
Thread.sleep(milsec);
} catch (final InterruptedException e) {

View File

@ -65,6 +65,7 @@ public class IODispatcher extends Thread {
this.mergeQueue = new ArrayBlockingQueue<MergeJob>(mergeQueueLength);
this.writeBufferSize = writeBufferSize;
this.terminate = false;
this.setName("IODispatcher");
}
public void terminate() {

View File

@ -107,11 +107,14 @@ public final class IndexCell<ReferenceType extends Reference> extends AbstractBu
this.writeBufferSize = writeBufferSize;
this.removeDelayedURLs = new TreeMap<byte[], HandleSet>(Word.commonHashOrder);
this.flushShallRun = true;
this.flushThread = new FlushThread();
this.flushThread = new FlushThread(cellPath.toString());
this.flushThread.start();
}
private class FlushThread extends Thread {
public FlushThread(String name) {
this.setName("IndexCell.FlushThread(" + name + ")");
}
@Override
public void run() {
while (IndexCell.this.flushShallRun) {

View File

@ -78,7 +78,7 @@ public final class InstantBusyThread extends AbstractBusyThread implements BusyT
throw new RuntimeException("serverInstantThread, wrong declaration of freemem: " + e.getMessage());
}
this.environment = (env instanceof Class<?>) ? null : env;
setName(theClass.getName() + "." + jobExec);
setName("BusyThread " + theClass.getName() + "." + jobExec);
this.handle = Long.valueOf(System.currentTimeMillis() + getName().hashCode());
}

View File

@ -1060,6 +1060,7 @@ public final class Protocol {
final int solrtimeout = Switchboard.getSwitchboard().getConfigInt(SwitchboardConstants.FEDERATED_SERVICE_SOLR_INDEXING_TIMEOUT, 6000);
Thread remoteRequest = new Thread() {
public void run() {
this.setName("Protocol.solrQuery(" + solrQuery.getQuery() + " to " + target.hash + ")");
try {
RemoteInstance instance = new RemoteInstance("http://" + address, null, "solr", solrtimeout); // this is a 'patch configuration' which considers 'solr' as default collection
try {

View File

@ -266,6 +266,7 @@ public class RemoteSearch extends Thread {
Thread secondary = new Thread() {
@Override
public void run() {
this.setName("RemoteSearch.secondaryRemoteSearch(" + wordhashes + " to " + targethash + ")");
event.oneFeederStarted();
try {
int urls = Protocol.secondarySearch(
@ -318,6 +319,7 @@ public class RemoteSearch extends Thread {
Thread solr = new Thread() {
@Override
public void run() {
this.setName("RemoteSearch.solrRemoteSearch(" + solrQuery.getQuery() + " to " + targetPeer.hash + ")");
int urls = 0;
try {
event.oneFeederStarted();

View File

@ -139,6 +139,7 @@ public class WebStructureGraph {
private class PublicRefDNSResolvingProcess extends Thread {
private PublicRefDNSResolvingProcess() {
this.setName("WebStructureGraph.PublicRefDNSResolvingProcess");
}
@Override

View File

@ -48,6 +48,7 @@ public class MemoryTracker extends Thread {
public MemoryTracker(final long time) {
this.delaytime = time;
running = true;
this.setName("MemoryTracker");
}
public void run() {

View File

@ -1148,6 +1148,7 @@ public final class Switchboard extends serverSwitch {
// finally start jobs which shall be started after start-up
new Thread() {
public void run() {
Thread.currentThread().setName("Switchboard.setHttpServer");
try {Thread.sleep(10000);} catch (final InterruptedException e) {} // needs httpd up
execAPIActions(); // trigger startup actions
}

View File

@ -316,6 +316,7 @@ public final class SearchEvent {
new Thread() {
@Override
public void run() {
this.setName("SearchEvent.init(" + query.getQueryGoal().getQueryString(false) + ")");
Thread.currentThread().setName("SearchEvent.primaryRemoteSearches");
RemoteSearch.primaryRemoteSearches(
SearchEvent.this,