List of usage examples for java.lang Thread setName
public final synchronized void setName(String name)
From source file:com.sittinglittleduck.DirBuster.Manager.java
public void start() { try {//from w w w .jav a 2 s. c o m timestarted = System.currentTimeMillis(); totalDirsFound = 0; producedBasesCases.clear(); numberOfBaseCasesProduced = 0; parsedLinksProcessed = 0; processedLinks.clear(); task = new ProcessChecker(this); timer.scheduleAtFixedRate(task, 1000L, 1000L); task2 = new ProcessEnd(this); timer.scheduleAtFixedRate(task2, 30000L, 30000L); // start the pure brute force thread if (pureBrute) { // start the work generator workGenThread = new Thread(workGenBrute); } // start the else if (urlFuzz) { workGenThread = new Thread(workGenFuzz); } else if (pureBrutefuzz) { workGenThread = new Thread(workGenBruteFuzz); } else { // start the work generator workGenThread = new Thread(workGen); } workGenThread.setName("DirBuster-WorkerGenerator"); workGenThread.start(); // add the worker and parseWorker threads for (int i = 0; i < workers.size(); i++) { Thread workerThread = new Thread(((Worker) workers.elementAt(i))); workerThread.setName("DirBuster-Worker"); workerThread.start(); ((HTMLparse) parseWorkers.elementAt(i)).start(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.google.dart.compiler.metrics.Tracer.java
private BlockingQueue<TraceEvent> openLogWriter(final Writer writer, final String fileName) { try {//from w w w.j a v a 2 s . c o m if (outputFormat.equals(Format.HTML)) { writer.write("<HTML isdump=\"true\"><body>" + "<style>body {font-family:Helvetica; margin-left:15px;}</style>" + "<h2>Performance dump from GWT</h2>" + "<div>This file contains data that can be viewed with the " + "<a href=\"http://code.google.com/speedtracer\">SpeedTracer</a> " + "extension under the <a href=\"http://chrome.google.com/\">" + "Chrome</a> browser.</div><p><span id=\"info\">" + "(You must install the SpeedTracer extension to open this file)</span></p>" + "<div style=\"display: none\" id=\"traceData\" version=\"0.17\">\n"); } } catch (IOException e) { System.err .println("Unable to write to dart.speedtracerlog '" + (fileName == null ? "" : fileName) + "'"); e.printStackTrace(); return null; } final BlockingQueue<TraceEvent> eventQueue = new LinkedBlockingQueue<TraceEvent>(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { // Wait for the other thread to drain the queue. eventQueue.add(shutDownSentinel); shutDownLatch.await(); } catch (InterruptedException e) { // Ignored } } }); // Background thread to write SpeedTracer events to log Thread logWriterWorker = new LogWriterThread(writer, fileName, eventQueue); // Lower than normal priority. logWriterWorker.setPriority((Thread.MIN_PRIORITY + Thread.NORM_PRIORITY) / 2); /* * This thread must be daemon, otherwise shutdown hooks would never begin to * run, and an app wouldn't finish. */ logWriterWorker.setDaemon(true); logWriterWorker.setName("SpeedTracerLogger writer"); logWriterWorker.start(); return eventQueue; }
From source file:com.hubcap.task.TaskRunner.java
/** * Processes the 'START' state/*from w w w . j a va2s . c o m*/ */ protected void processStateStart() { if (this.taskState == TaskRunnerState.START) { if (helperPool == null) { // get a stable thread count up to MAX_HELPER_THREADS based on // CPU LOAD per helper int maxHelpers = ThreadUtils.getStableThreadCount(CPU_LOAD_TRH, CPU_WAIT_TRH, CPU_COMPUTE_TRH, Constants.MAX_HELPER_THREADS); if (this.helperFactory == null) { this.helperFactory = new ThreadFactory() { @Override public Thread newThread(Runnable r) { if (helpers.contains(r)) { throw new IllegalStateException("Cannot add duplicate runnable to running tasks"); } Thread thread = new Thread(r); thread.setDaemon(false); thread.setName("TaskRunnerHelper-" + helperCount.getAndIncrement()); taskThreads.add(thread); return thread; } }; } // create the pool but don't fire up any helpers helperPool = Executors.newFixedThreadPool(maxHelpers, TaskRunner.taskRunnerThreadFactory); } TaskRunnerListener[] list = listeners.toArray(new TaskRunnerListener[listeners.size()]); for (int i = 0; i < list.length; i++) { TaskRunnerListener listener = list[i]; listener.onTaskStart(this); } try { // create the task model using the input arguments setTaskState(TaskRunnerState.ACTIVE); this.taskModel = CLIOptionBuilder.buildInputOptionsModel(this.taskArgs); synchronized (sharedResource_resultModel) { sharedResource_resultModel.addTaskModel(taskModel); } } catch (ParseException e) { ErrorUtils.printStackTrace(e); setTaskState(TaskRunnerState.ERROR); this.canRecoverFromError = true; this.errorMessage = "Inputs were malformed, please try again"; } } else { System.err.println("Can't Start...Task State is: " + this.taskState); } }
From source file:com.coinblesk.payments.WalletService.java
private void fetchExchangeRate() { Thread t = bitcoinjThreadFactory.newThread(new ExchangeRateFetcher(fiatCurrency, walletServiceBinder)); t.setName("WalletService.ExchangeRateFetcher"); t.start();/*from w w w . j a v a2 s. c o m*/ }
From source file:org.apache.nifi.bootstrap.RunNiFi.java
public RunNiFi(final File bootstrapConfigFile, final boolean verbose) throws IOException { this.bootstrapConfigFile = bootstrapConfigFile; loggingExecutor = Executors.newFixedThreadPool(2, new ThreadFactory() { @Override/* w w w . ja va2s. c om*/ public Thread newThread(final Runnable runnable) { final Thread t = Executors.defaultThreadFactory().newThread(runnable); t.setDaemon(true); t.setName("NiFi logging handler"); return t; } }); serviceManager = loadServices(); }
From source file:org.apache.stratos.common.internal.StratosCommonServiceComponent.java
protected void activate(ComponentContext context) { try {//ww w. ja v a 2 s. c o m final BundleContext bundleContext = context.getBundleContext(); if (CommonUtil.getStratosConfig() == null) { StratosConfiguration stratosConfig = CommonUtil.loadStratosConfiguration(); CommonUtil.setStratosConfig(stratosConfig); } // Loading the EULA if (CommonUtil.getEula() == null) { String eula = CommonUtil.loadTermsOfUsage(); CommonUtil.setEula(eula); } AxisConfiguration axisConfig = ServiceReferenceHolder.getInstance().getAxisConfiguration(); if ((axisConfig != null) && (axisConfig.getClusteringAgent() != null)) { Thread thread = new Thread() { @Override public void run() { try { // Wait for the hazelcast instance to be available long startTime = System.currentTimeMillis(); log.info("Waiting for the hazelcast instance to be initialized..."); while (ServiceReferenceHolder.getInstance().getHazelcastInstance() == null) { Thread.sleep(1000); if ((System.currentTimeMillis() - startTime) >= StratosConstants.HAZELCAST_INSTANCE_INIT_TIMEOUT) { throw new RuntimeException("Hazelcast instance was not initialized within " + StratosConstants.HAZELCAST_INSTANCE_INIT_TIMEOUT / 1000 + " seconds"); } } registerDistributedObjectProviderService(bundleContext); } catch (Exception e) { log.error(e); } } }; thread.setName("Distributed object provider registration thread"); thread.start(); } else { // Register distributed object provider service registerDistributedObjectProviderService(bundleContext); } // Register manager configuration service try { StratosConfiguration stratosConfiguration = CommonUtil.loadStratosConfiguration(); bundleContext.registerService(StratosConfiguration.class.getName(), stratosConfiguration, null); } catch (Exception ex) { String msg = "An error occurred while registering stratos configuration service"; log.error(msg, ex); } if (log.isInfoEnabled()) { log.info("Stratos common service component is activated"); } } catch (Exception e) { log.error("Error in activating stratos common service component", e); } }
From source file:com.raphfrk.craftproxyclient.gui.CraftProxyGUI.java
public void init() { this.setVisible(true); Thread t = new Thread(new Runnable() { public void run() { final JSONObject loginDetails = GUIManager.getLoginDetails(); SwingUtilities.invokeLater(new Runnable() { public void run() { if (loginDetails == null) { JOptionPane.showMessageDialog(CraftProxyGUI.this, "Login failed"); dispose();/* w w w . j a v a 2 s. com*/ } else { connect.setText("Start"); setStatus("Logged in as " + AuthManager.getUsername()); if (!"".equals(serverName.getText())) { if (!closed) { startProxyServer(); } else { dispose(); } } } } }); } }); t.setName("GUI Init thread"); t.start(); }
From source file:org.dasein.cloud.tier3.APIHandler.java
public @Nonnull APIResponse get(final @Nonnull String operation, final @Nonnull String resource, final @Nullable String id, final @Nullable NameValuePair... parameters) { final APIResponse apiResponse = new APIResponse(); Thread t = new Thread() { @Override//from w w w . ja va 2 s.co m public void run() { try { APITrace.begin(provider, operation); try { try { get(apiResponse, null, 1, resource, id, parameters); } catch (Throwable t) { apiResponse.receive(new CloudException(t)); } } finally { APITrace.end(); } } finally { provider.release(); } } }; t.setName(operation); t.setDaemon(true); provider.hold(); t.start(); return apiResponse; }
From source file:io.reign.zk.ResilientZkClient.java
synchronized void spawnReconnectThread() { if (zooKeeper == null || zooKeeper.getState() == ZooKeeper.States.CLOSED) { // do connection in another thread so as to not block the ZK event thread Thread reconnectThread = new Thread() { @Override/*from w ww . ja v a 2 s . c o m*/ public void run() { connect(backoffStrategyFactory.get(), true); } }; reconnectThread .setName(this.getClass().getSimpleName() + ".zkConnectThread-" + reconnectThread.hashCode()); reconnectThread.setPriority(Thread.MIN_PRIORITY); reconnectThread.run(); } }
From source file:com.android.exchange.SyncManager.java
static public void reloadFolderList(Context context, long accountId, boolean force) { SyncManager syncManager = INSTANCE;/* w w w. j av a 2 s. co m*/ if (syncManager == null) return; Cursor c = context.getContentResolver().query(Mailbox.CONTENT_URI, Mailbox.CONTENT_PROJECTION, MailboxColumns.ACCOUNT_KEY + "=? AND " + MailboxColumns.TYPE + "=?", new String[] { Long.toString(accountId), Long.toString(Mailbox.TYPE_EAS_ACCOUNT_MAILBOX) }, null); try { if (c.moveToFirst()) { synchronized (sSyncLock) { Mailbox m = new Mailbox().restore(c); Account acct = Account.restoreAccountWithId(context, accountId); if (acct == null) { reloadFolderListFailed(accountId); return; } String syncKey = acct.mSyncKey; // No need to reload the list if we don't have one if (!force && (syncKey == null || syncKey.equals("0"))) { reloadFolderListFailed(accountId); return; } // Change all ping/push boxes to push/hold ContentValues cv = new ContentValues(); cv.put(Mailbox.SYNC_INTERVAL, Mailbox.CHECK_INTERVAL_PUSH_HOLD); context.getContentResolver().update(Mailbox.CONTENT_URI, cv, WHERE_PUSH_OR_PING_NOT_ACCOUNT_MAILBOX, new String[] { Long.toString(accountId) }); log("Set push/ping boxes to push/hold"); long id = m.mId; AbstractSyncService svc = syncManager.mServiceMap.get(id); // Tell the service we're done if (svc != null) { synchronized (svc.getSynchronizer()) { svc.stop(); } // Interrupt the thread so that it can stop Thread thread = svc.mThread; thread.setName(thread.getName() + " (Stopped)"); thread.interrupt(); // Abandon the service syncManager.releaseMailbox(id); // And have it start naturally kick("reload folder list"); } } } } finally { c.close(); } }