List of usage examples for java.lang Thread setName
public final synchronized void setName(String name)
From source file:eagle.jobrunning.crawler.RunningJobCrawlerImpl.java
private void startJobConfigProcessThread() { int configThreadCount = DEFAULT_CONFIG_THREAD_COUNT; LOG.info("Job Config crawler main thread started, pool size: " + DEFAULT_CONFIG_THREAD_COUNT); ThreadFactory factory = new ThreadFactory() { private final AtomicInteger count = new AtomicInteger(0); public Thread newThread(Runnable runnable) { count.incrementAndGet();/* www .j a v a 2 s.co m*/ Thread thread = Executors.defaultThreadFactory().newThread(runnable); thread.setName("config-crawler-workthread-" + count.get()); return thread; } }; ThreadPoolExecutor pool = new ThreadPoolExecutor(configThreadCount, configThreadCount, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), factory); while (true) { JobContext context; try { context = queueOfConfig.take(); LOG.info("queueOfConfig size: " + queueOfConfig.size()); Runnable configCrawlerThread = new ConfigWorkTask(new JobContext(context), fetcher, callback, this); pool.execute(configCrawlerThread); } catch (InterruptedException e) { LOG.warn("Got an InterruptedException: " + e.getMessage()); } catch (RejectedExecutionException e2) { LOG.warn("Got RejectedExecutionException: " + e2.getMessage()); } catch (Throwable t) { LOG.warn("Got an throwable t, " + t.getMessage()); } } }
From source file:msearch.filmeSuchen.sender.MediathekOrf.java
@Override void addToList() { MSStringBuilder seite = new MSStringBuilder(MSConst.STRING_BUFFER_START_BUFFER); listeThemen.clear();/*www . j ava2 s. com*/ meldungStart(); if (MSConfig.senderAllesLaden) { bearbeiteAdresseSendung(seite); } bearbeiteAdresseThemen(seite); listeSort(listeThemen, 1); int maxTage = MSConfig.senderAllesLaden ? 9 : 2; for (int i = 0; i < maxTage; ++i) { String vorTagen = getGestern(i).toLowerCase(); bearbeiteAdresseTag("http://tvthek.orf.at/schedule/" + vorTagen, seite); } if (MSConfig.getStop()) { meldungThreadUndFertig(); } else if (listeThemen.size() == 0) { meldungThreadUndFertig(); } else { meldungAddMax(listeThemen.size()); for (int t = 0; t < maxThreadLaufen; ++t) { //new Thread(new ThemaLaden()).start(); Thread th = new Thread(new ThemaLaden()); th.setName(SENDERNAME + t); th.start(); } } }
From source file:com.github.vatbub.awsvpnlauncher.Main.java
/** * Copies {@code System.in} to new {@code InputStream}. Filters {@code CrLf}s ({@code \r\n} in Java) out and replaces them with a single {@code \n} ({@code \n} in Java) * * @return The {@code InputStream} to which the filtered contents are forwarded to. * @throws IOException If {@code System.in} cannot be read for any reason *///from w ww .j av a 2 s .c o m private static InputStream copyAndFilterInputStream() throws IOException { PipedOutputStream forwardTo = new PipedOutputStream(); PipedInputStream res = new PipedInputStream(forwardTo); Thread pipeThread = new Thread(() -> { while (true) { try { char ch = (char) System.in.read(); if (ch != '\r' && !SystemUtils.IS_OS_MAC) { forwardTo.write((int) ch); } } catch (IOException e) { FOKLogger.log(Main.class.getName(), Level.SEVERE, "Stopped forwarding System in due to an exception", e); break; } } }); pipeThread.setName("pipeThread"); pipeThread.start(); return res; }
From source file:com.nesscomputing.syslog4j.impl.AbstractSyslog.java
public Thread createWriterThread(AbstractSyslogWriter syslogWriter) { Thread newWriterThread = new Thread(syslogWriter); newWriterThread.setName("SyslogWriter: " + getProtocol()); newWriterThread.setDaemon(syslogConfig.isUseDaemonThread()); if (syslogConfig.getThreadPriority() > -1) { newWriterThread.setPriority(syslogConfig.getThreadPriority()); }/* w ww . ja v a2 s . com*/ syslogWriter.setThread(newWriterThread); newWriterThread.start(); return newWriterThread; }
From source file:com.alibaba.napoli.gecko.service.timer.ThreadRenamingRunnable.java
public void run() { final Thread currentThread = Thread.currentThread(); final String oldThreadName = currentThread.getName(); final String newThreadName = this.proposedThreadName; // Change the thread name before starting the actual runnable. boolean renamed = false; if (!oldThreadName.equals(newThreadName)) { try {/*from w w w .j ava 2 s . c om*/ currentThread.setName(newThreadName); renamed = true; } catch (SecurityException e) { logger.debug("Failed to rename a thread " + "due to security restriction.", e); } } // Run the actual runnable and revert the name back when it ends. try { this.runnable.run(); } finally { if (renamed) { // Revert the name back if the current thread was renamed. // We do not check the exception here because we know it works. currentThread.setName(oldThreadName); } } }
From source file:org.deeplearning4j.arbiter.optimize.runner.BaseOptimizationRunner.java
protected void init() { futureListenerExecutor = Executors.newFixedThreadPool(maxConcurrentTasks(), new ThreadFactory() { private AtomicLong counter = new AtomicLong(0); @Override/*from w w w.ja v a 2 s. c o m*/ public Thread newThread(Runnable r) { Thread t = Executors.defaultThreadFactory().newThread(r); t.setDaemon(true); t.setName("ArbiterOptimizationRunner-" + counter.getAndIncrement()); return t; } }); }
From source file:com.ganji.cateye.flume.kestrel.KestrelRpcClient.java
License:asdf
public KestrelRpcClient() { stateLock = new ReentrantLock(true); connState = State.INIT;//from w w w . j a v a 2 s.c o m threadCounter = new AtomicLong(0); // OK to use cached threadpool, because this is simply meant to timeout // the calls - and is IO bound. callTimeoutPool = Executors.newCachedThreadPool(new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName(KestrelRpcClient.this.sinkName + "-" + String.valueOf(threadCounter.incrementAndGet())); return t; } }); }
From source file:charva.awt.Window.java
/** * Lay out the contained components, draw the window and its contained * components, and then read input events off the EventQueue and send * them to the component that has the input focus. *//*from w w w . j a v a2 s.c om*/ public void show() { if (_visible) return; // This window is already visible. _visible = true; _term.addWindow(this); /* call doLayout in Container superclass. This will lay out all of * the contained components (i.e. children) and their descendants, * and in the process will set the valid flag of all descendants. */ super.doLayout(); // call method in Container superclass this.adjustLocation(); // ensure it fits inside the screen this.draw(); /* Rather than call Toolkit.sync() directly here, we put a SyncEvent * onto the SyncQueue. The SyncThread will read it off the SyncQueue * and then sleep for 50msec before putting the SyncEvent onto * the EventQueue, from which it will be picked up by the active * Window (i.e. an instance of this class). The active Window * will then call Toolkit.sync() directly. This slight delay speeds * up the case where a window opens and then immediately opens a * new window (and another...). */ SyncQueue.getInstance().postEvent(new SyncEvent(this)); if (_dispatchThreadRunning) run(); else { _dispatchThreadRunning = true; Thread dispatchThread = new Thread(this); dispatchThread.setName("event dispatcher"); dispatchThread.start(); /* If "charva.script.playback" is defined, we start up * a thread for playing back the script. Keys from both the * script and the keyboard will cause "fireKeystroke()" to be * invoked. * The playback thread is started _after_ "addWindow()" is * called for the first time, to make sure that _windowList * is non-empty when the playback thread calls "fireKeystroke()". */ startPlayback(); } }
From source file:com.tascape.qa.th.Utils.java
/** * Executes command, and waits for the expected pass/fail phrase in console printout within timeout, * * @param command command line/*from ww w .jav a2 s. c o m*/ * @param pass skip checking if null * @param fail skip checking if null * @param timeout set 0 for not to check the output message, otherwise, waiting for timeout * @param workingDir working directory * * @return console output as a list of strings * * @throws IOException for command error * @throws InterruptedException when interrupted */ public static List<String> cmd(String[] command, final String pass, final String fail, final long timeout, final String workingDir) throws IOException, InterruptedException { ProcessBuilder pb = new ProcessBuilder(command); if (workingDir != null) { pb.directory(new File(workingDir)); } pb.redirectErrorStream(true); LOG.debug("Running command: " + pb.command().toString().replace(",", "")); final Process p = pb.start(); Thread thread; final List<String> output = new ArrayList<>(); if (timeout == 0) { LOG.debug("This is a start-and-exit command"); output.add(PASS); return output; } else { thread = new Thread() { @Override public void run() { try { LOG.debug("Command timeouts in {} ms", timeout); Thread.sleep(timeout); try { p.exitValue(); } catch (IllegalThreadStateException ex) { LOG.debug("killing subprocess {} - {}", p, ex.getMessage()); p.destroy(); } } catch (InterruptedException ex) { LOG.warn(ex.getMessage()); } } }; thread.setName(Thread.currentThread().getName() + "-" + p.hashCode()); thread.setDaemon(true); thread.start(); } BufferedReader stdIn = new BufferedReader(new InputStreamReader(p.getInputStream())); String c = p + " - "; for (String line = stdIn.readLine(); line != null;) { LOG.trace("{}{}", c, line); output.add(line); try { line = stdIn.readLine(); } catch (IOException ex) { LOG.warn(ex.getMessage()); break; } } LOG.debug("Command exit code {}", p.waitFor()); thread.interrupt(); try { stdIn.close(); } catch (IOException ex) { LOG.warn("", ex); } for (String s : output) { if (pass != null && (s.contains(pass) || s.matches(pass))) { output.add(PASS); break; } else if (fail != null && s.contains(fail)) { output.add(FAIL); break; } } return output; }
From source file:com.zimbra.cs.store.file.BlobDeduper.java
public void process(List<Short> volumeIds) throws ServiceException, IOException { synchronized (this) { if (inProgress) { throw MailServiceException .TRY_AGAIN("Dedupe is already in progress. Only one request can be run at a time."); }/*from w w w . j ava 2 s. com*/ inProgress = true; totalLinksCreated = 0; totalSizeSaved = 0; volumeBlobsProgress.clear(); blobDigestsProgress.clear(); } Thread thread = new BlobDeduperThread(volumeIds); thread.setName("BlobDeduper"); thread.start(); }