List of usage examples for java.lang Thread setName
public final synchronized void setName(String name)
From source file:immf.SendMailPicker.java
public SendMailPicker(Config conf, ServerMain server, ImodeNetClient client, StatusManager status) { this.conf = conf; this.server = server; this.client = client; this.status = status; this.forcePlainText = conf.isSenderMailForcePlainText(); this.isForwardSent = conf.isForwardSent(); if (true) {// ww w . jav a 2 s . c om Thread t = new Thread(this); t.setName("SendMailPicker"); t.setDaemon(true); t.start(); } }
From source file:org.netflux.core.task.AbstractTask.java
public void start() { // TODO: Thread handling // TODO: Improve uncaught exception handling Thread taskWorker = this.getTaskWorker(); taskWorker.setName(this.getName()); taskWorker.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread thread, Throwable throwable) { String message = MessageFormat .format(AbstractTask.messages.getString("exception.uncaught.exception"), thread.getName()); AbstractTask.log.error(message, throwable); for (OutputPort outputPort : AbstractTask.this.outputPorts.values()) { outputPort.consume(Record.END_OF_DATA); }/* w ww . j a v a2 s .co m*/ } }); taskWorker.start(); }
From source file:TransformApplet.java
public void init() { tf = TransformerFactory.newInstance(); try {//from ww w . j a va 2 s. c o m tf.setAttribute("use-classpath", Boolean.TRUE); } catch (IllegalArgumentException iae) { System.err.println( "Could not set XSLTC-specific TransformerFactory" + " attributes. Transformation failed."); } // Another thread is created to keep the context class loader // information. When use JDK 1.4 plugin for browser, to get around the // problem with the bundled old version of xalan and endorsed class // loading mechanism transformThread = new TransformDelegate(true); Thread t = new Thread(transformThread); t.setName("transformThread"); t.start(); }
From source file:org.apache.apex.malhar.lib.io.WebSocketInputOperator.java
@Override public void run() { try {//from w w w.j a v a 2s. com connectionClosed = false; AsyncHttpClientConfigBean config = new AsyncHttpClientConfigBean(); config.setIoThreadMultiplier(ioThreadMultiplier); config.setApplicationThreadPool(Executors.newCachedThreadPool(new ThreadFactory() { private long count = 0; @Override public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName(ClassUtils.getShortClassName(this.getClass()) + "-AsyncHttpClient-" + count++); return t; } })); if (client != null) { client.closeAsynchronously(); } client = new AsyncHttpClient(config); connection = client.prepareGet(uri.toString()).execute( new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketTextListener() { @Override public void onMessage(String string) { try { T o = convertMessage(string); if (!(skipNull && o == null)) { outputPort.emit(o); } } catch (IOException ex) { LOG.error("Got exception: ", ex); } } @Override public void onOpen(WebSocket ws) { LOG.debug("Connection opened"); } @Override public void onClose(WebSocket ws) { LOG.debug("Connection connectionClosed."); connectionClosed = true; } @Override public void onError(Throwable t) { LOG.error("Caught exception", t); } }).build()).get(5, TimeUnit.SECONDS); } catch (Exception ex) { LOG.error("Error reading from " + uri, ex); if (client != null) { client.close(); } connectionClosed = true; } }
From source file:com.datatorrent.lib.io.WebSocketInputOperator.java
@Override public void run() { try {/* ww w .j av a 2 s . c o m*/ connectionClosed = false; AsyncHttpClientConfigBean config = new AsyncHttpClientConfigBean(); config.setIoThreadMultiplier(ioThreadMultiplier); config.setApplicationThreadPool(Executors.newCachedThreadPool(new ThreadFactory() { private long count = 0; @Override public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName(ClassUtils.getShortClassName(this.getClass()) + "-AsyncHttpClient-" + count++); return t; } })); if (client != null) { client.closeAsynchronously(); } client = new AsyncHttpClient(config); connection = client.prepareGet(uri.toString()).execute( new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketTextListener() { @Override public void onMessage(String string) { LOG.debug("Got: " + string); try { T o = convertMessage(string); if (!(skipNull && o == null)) { outputPort.emit(o); } } catch (IOException ex) { LOG.error("Got exception: ", ex); } } @Override public void onOpen(WebSocket ws) { LOG.debug("Connection opened"); } @Override public void onClose(WebSocket ws) { LOG.debug("Connection connectionClosed."); connectionClosed = true; } @Override public void onError(Throwable t) { LOG.error("Caught exception", t); } }).build()).get(5, TimeUnit.SECONDS); } catch (Exception ex) { LOG.error("Error reading from " + uri, ex); if (client != null) { client.close(); } connectionClosed = true; } }
From source file:org.noroomattheinn.utils.ThreadManager.java
public synchronized Thread launch(Runnable r, String name) { if (shuttingDown) return null; Thread t = new Thread(r); if (name == null) name = String.valueOf(threadID++); t.setName("00 VT - " + name); t.setDaemon(true);//from w ww . ja v a2 s . c o m t.start(); threads.add(t); // Clean out any old terminated threads... Iterator<Thread> i = threads.iterator(); while (i.hasNext()) { Thread cur = i.next(); if (cur.getState() == Thread.State.TERMINATED) { i.remove(); } } return t; }
From source file:at.sti2.sparkwave.SparkwaveKernel.java
/** * Starts all relevant threads for a pattern and keeps track of them * @param pattern/*from ww w .jav a2s .c o m*/ */ public void addProcessorThread(Pattern pattern) { //Create SparkwaveNetwork SparkwaveNetwork sparkwaveNetwork = new SparkwaveNetwork(pattern); sparkwaveNetwork.init(); //Every pattern gets its own queue BlockingQueue<Triple> queue = new ArrayBlockingQueue<Triple>(10); queues.add(queue); //Create SparkwaveProcessorThread ProcessorThread sparkwaveProcessor = new ProcessorThread(sparkwaveNetwork, queue); Thread thread = new Thread(sparkwaveProcessor); thread.setName("Processor-" + thread.getName()); thread.start(); patternThreadMap.put(pattern, thread); patternQueueMap.put(pattern, queue); idPatternMap.put(pattern.getId(), pattern); }
From source file:mServer.search.MserverSearch.java
@SuppressWarnings("deprecation") public boolean filmeSuchen(MserverSearchTask aktSearchTask) { boolean ret = true; try {/* w w w .j a va2 s. c o m*/ // =========================================== // den nchsten Suchlauf starten MserverLog.systemMeldung(""); MserverLog.systemMeldung("-----------------------------------"); MserverLog.systemMeldung("Filmsuche starten"); crawler = new Crawler(); // was und wie CrawlerConfig.senderLoadHow = aktSearchTask.loadHow(); CrawlerConfig.updateFilmliste = aktSearchTask.updateFilmliste(); CrawlerConfig.nurSenderLaden = arrLesen(aktSearchTask.arr[MserverSearchTask.SUCHEN_SENDER_NR].trim()); CrawlerConfig.orgFilmlisteErstellen = aktSearchTask.orgListeAnlegen(); CrawlerConfig.orgFilmliste = MserverDaten.system[MserverKonstanten.SYSTEM_FILMLISTE_ORG_NR]; // live-steams CrawlerConfig.importLive = MserverDaten.system[MserverKonstanten.SYSTEM_IMPORT_LIVE_NR]; // und noch evtl. ein paar Imports von Filmlisten anderer Server CrawlerConfig.importUrl_1__anhaengen = MserverDaten.system[MserverKonstanten.SYSTEM_IMPORT_URL_1_NR]; CrawlerConfig.importUrl_2__anhaengen = MserverDaten.system[MserverKonstanten.SYSTEM_IMPORT_URL_2_NR]; // fr die alte Filmliste CrawlerConfig.importOld = MserverDaten.system[MserverKonstanten.SYSTEM_IMPORT_OLD_NR]; CrawlerConfig.importAkt = MserverDatumZeit .getNameAkt(MserverDaten.system[MserverKonstanten.SYSTEM_IMPORT_AKT_NR]); // Rest Config.setUserAgent(MserverDaten.getUserAgent()); CrawlerConfig.proxyUrl = MserverDaten.system[MserverKonstanten.SYSTEM_PROXY_URL_NR]; CrawlerConfig.proxyPort = MserverDaten.getProxyPort(); Config.debug = MserverDaten.debug; Log.setLogfile(MserverDaten.getLogDatei(MserverKonstanten.LOG_FILE_NAME_MSEARCH)); Thread t = new Thread(crawler); t.setName("Crawler"); t.start(); MserverLog.systemMeldung("Filme suchen gestartet"); // =========================================== // warten auf das Ende //int warten = aktSearchTask.allesLaden() == true ? MvSKonstanten.WARTEZEIT_ALLES_LADEN : MvSKonstanten.WARTEZEIT_UPDATE_LADEN; int warten = aktSearchTask.getWaitTime()/*Minuten*/; MserverLog.systemMeldung("Max Laufzeit[Min]: " + warten); MserverLog.systemMeldung("-----------------------------------"); TimeUnit.MINUTES.timedJoin(t, warten); // =========================================== // erst mal schauen ob noch was luft if (t != null) { if (t.isAlive()) { MserverLog.fehlerMeldung(915147623, MserverSearch.class.getName(), "Der letzte Suchlauf luft noch"); if (crawler != null) { MserverLog.systemMeldung(""); MserverLog.systemMeldung(""); MserverLog.systemMeldung("================================"); MserverLog.systemMeldung("================================"); MserverLog.systemMeldung("und wird jetzt gestoppt"); MserverLog.systemMeldung( "Zeit: " + FastDateFormat.getInstance("dd.MM.yyyy HH:mm:ss").format(new Date())); MserverLog.systemMeldung("================================"); MserverLog.systemMeldung("================================"); MserverLog.systemMeldung(""); //und jetzt STOPPEN!!!!!!!! crawler.stop(); } int w; if (loadLongMax()) w = 30; // 30 Minuten bei langen Lufen else w = 20;// 20 Minuten warten, das Erstellen/Komprimieren der Liste dauert TimeUnit.MINUTES.timedJoin(t, w); if (t.isAlive()) { MserverLog.systemMeldung(""); MserverLog.systemMeldung(""); MserverLog.systemMeldung("================================"); MserverLog.systemMeldung("================================"); MserverLog.systemMeldung("und noch gekillt"); MserverLog.systemMeldung( "Zeit: " + FastDateFormat.getInstance("dd.MM.yyyy HH:mm:ss").format(new Date())); MserverLog.systemMeldung("================================"); MserverLog.systemMeldung("================================"); MserverLog.systemMeldung(""); ret = false; } //jetzt ist Schicht im Schacht t.stop(); } } } catch (Exception ex) { MserverLog.fehlerMeldung(636987308, MserverSearch.class.getName(), "filmeSuchen", ex); } int l = crawler.getListeFilme().size(); MserverLog.systemMeldung(""); MserverLog.systemMeldung(""); MserverLog.systemMeldung("================================"); MserverLog.systemMeldung("Filmliste Anzahl Filme: " + l); if (l < 10_000) { //dann hat was nicht gepasst MserverLog.systemMeldung(" Fehler!!"); MserverLog.systemMeldung("================================"); ret = false; } else { MserverLog.systemMeldung(" dann ist alles OK"); MserverLog.systemMeldung("================================"); } MserverLog.systemMeldung("filmeSuchen beendet"); crawler = null; return ret; }
From source file:org.apache.activemq.tool.sampler.AbstractPerformanceSampler.java
@Override public void startSampler(CountDownLatch completionLatch, ClientRunBasis clientRunBasis, long clientRunDuration) { Validate.notNull(clientRunBasis);/*from w w w . j av a 2 s . com*/ Validate.notNull(completionLatch); if (clientRunBasis == ClientRunBasis.time) { // override the default durations // if the user has overridden a duration, then use that duration = (duration == null) ? clientRunDuration : this.duration; rampUpTime = (rampUpTime == null) ? (duration / 100 * rampUpPercent) : this.rampUpTime; rampDownTime = (rampDownTime == null) ? (duration / 100 * rampDownPercent) : this.rampDownTime; Validate.isTrue(duration >= (rampUpTime + rampDownTime), "Ramp times (up: " + rampDownTime + ", down: " + rampDownTime + ") exceed the sampler duration (" + duration + ")"); log.info("Sampling duration: {} ms, ramp up: {} ms, ramp down: {} ms", duration, rampUpTime, rampDownTime); // spawn notifier thread to stop the sampler, taking ramp-down time into account Thread notifier = new Thread(new RampDownNotifier(this)); notifier.setName("RampDownNotifier[" + this.getClass().getSimpleName() + "]"); notifier.start(); } else { log.info("Performance test running on count basis; ignoring duration and ramp times"); setRampUpTime(0); setRampDownTime(0); } this.completionLatch = completionLatch; Thread t = new Thread(this); t.setName(this.getClass().getSimpleName()); t.start(); isRunning.set(true); }
From source file:org.berlin.crawl.bom.BotTrueCrawler.java
public void launch() { // Each bot crawler will launch in a separate thread // // Each true crawler will have a blocking queue for added // bot links to process loadIgnores();//from ww w .j a v a 2 s . c o m final BotTrueCrawlerThread thread = new BotTrueCrawlerThread(); final Thread t = new Thread(thread); final String mngl = (this.firstLink.getHost().length() >= 12) ? this.firstLink.getHost().substring(0, 10) : this.firstLink.getHost(); t.setName(t.getName() + "-TrueCrawl-" + mngl); t.start(); queue.launchReportSystem(); }