List of usage examples for java.lang Thread getName
public final String getName()
From source file:com.aerofs.baseline.DefaultUncaughtExceptionHandler.java
@Override public void uncaughtException(Thread t, Throwable e) { if (e instanceof JsonProcessingException) { LOGGER.error("fail parse configuration file with error \"{}\"", ((JsonProcessingException) e).getOriginalMessage(), e); System.exit(Constants.INVALID_CONFIGURATION_EXIT_CODE); } else if (e instanceof ConstraintViolationException) { LOGGER.error("invalid configuration with violations\"{}\"", e.getMessage(), e); System.exit(Constants.INVALID_CONFIGURATION_EXIT_CODE); } else {//from w ww .j a v a 2 s . co m LOGGER.error("fail catch exception thd:{}", t.getName(), e); System.exit(Constants.UNCAUGHT_EXCEPTION_ERROR_CODE); } }
From source file:org.nd4j.linalg.jcublas.context.ContextHolder.java
/** * Get the stream for the current thread * based on the device for the thread//w ww .j ava 2 s .c o m * @return the stream for the device and * thread */ public synchronized cudaStream_t getCudaStream() { Thread currentThread = Thread.currentThread(); CUcontext ctx = getContext(getDeviceForThread(), currentThread.getName()); cudaStream_t stream = cudaStreams.get(ctx, currentThread.getName()); if (stream == null) { stream = new cudaStream_t(); checkResult(JCudaDriver.cuCtxSetCurrent(ctx)); JCuda.cudaStreamCreate(stream); checkResult(JCuda.cudaStreamCreate(stream)); cudaStreams.put(ctx, currentThread.getName(), stream); } return stream; }
From source file:org.wso2.carbon.automation.extensions.jmeter.JMeterTestManager.java
private String executeTest(File test) throws Exception { String reportFileName;//from www . ja va 2s. co m String reportFileFullPath; JMeter jmeterInstance = new JMeter(); try { log.info("Executing test: " + test.getCanonicalPath()); reportFileName = test.getName().substring(0, test.getName().lastIndexOf(".")) + "-" + fmt.format(new Date()) + ".jmeterResult" + ".jtl"; File reportDir = JMeterInstallationProvider.getInstance().getReportDir(); reportFileFullPath = reportDir.toString() + File.separator + reportFileName; List<String> argsTmp = Arrays.asList("-n", "-t", test.getCanonicalPath(), "-l", reportDir.toString() + File.separator + reportFileName, "-p", jmeterProps.toString(), "-d", jmeterHome.getCanonicalPath(), "-L", "jorphan=" + jmeterLogLevel, "-L", "jmeter.util=" + jmeterLogLevel); List<String> args = new ArrayList<String>(); args.addAll(argsTmp); SecurityManager oldManager = System.getSecurityManager(); UncaughtExceptionHandler oldHandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { if (e instanceof ExitException && ((ExitException) e).getCode() == 0) { return; //Ignore } log.error("Error in thread " + t.getName()); } }); try { logParamsAndProps(args); jmeterInstance.start(args.toArray(new String[] {})); BufferedReader in = new BufferedReader( new InputStreamReader(new FileInputStream(jmeterLogFile), Charset.defaultCharset())); while (!checkForEndOfTest(in)) { try { Thread.sleep(1000); } catch (InterruptedException e) { break; } } } catch (ExitException e) { if (e.getCode() != 0) { throw new Exception("Test failed", e); } } catch (Exception e) { log.error(e); } finally { System.setSecurityManager(oldManager); Thread.setDefaultUncaughtExceptionHandler(oldHandler); } } catch (IOException e) { throw new Exception("Can't execute test", e); } return reportFileFullPath; }
From source file:org.jumpmind.symmetric.io.stage.StagedResource.java
public void setState(State state) { if (file.exists()) { File newFile = buildFile(state); if (!newFile.equals(file)) { if (newFile.exists()) { if (writer != null || outputStream != null) { throw new IoException("Could not write '{}' it is currently being written to", newFile.getAbsolutePath()); }//from w w w.j a va 2s.com if (!FileUtils.deleteQuietly(newFile)) { log.warn("Failed to delete '{}' in preparation for renaming '{}'", newFile.getAbsolutePath(), file.getAbsoluteFile()); if (readers.size() > 0) { for (Thread thread : readers.keySet()) { BufferedReader reader = readers.get(thread); log.warn("Closing unwanted reader for '{}' that had been created on thread '{}'", newFile.getAbsolutePath(), thread.getName()); IOUtils.closeQuietly(reader); } } if (!FileUtils.deleteQuietly(newFile)) { log.warn("Failed to delete '{}' for a second time", newFile.getAbsolutePath()); } } } if (!file.renameTo(newFile)) { String msg = String.format( "Had trouble renaming file. The current name is %s and the desired state was %s", file.getAbsolutePath(), state); log.warn(msg); throw new IllegalStateException(msg); } else { this.file = newFile; } } } else if (memoryBuffer != null && state == State.DONE) { this.memoryBuffer.setLength(0); this.memoryBuffer = null; } refreshLastUpdateTime(); this.state = state; }
From source file:uk.ac.ebi.fg.annotare2.web.server.services.MessengerImpl.java
@Override public void send(String note, Throwable x, User user) { try {/* w ww . ja v a 2 s . co m*/ Thread currentThread = Thread.currentThread(); String hostName = "unknown"; try { InetAddress localMachine = InetAddress.getLocalHost(); hostName = localMachine.getHostName(); } catch (UnknownHostException xx) { log.error("Unable to obtain a hostname", xx); } send(EXCEPTION_REPORT_TEMPLATE, ImmutableMap.of("application.host", hostName, "application.thread", currentThread.getName(), "exception.note", note, "exception.message", (null != x && null != x.getMessage()) ? x.getMessage() : "", "exception.stack", getStackTrace(x)), user, null, true); } catch (Throwable xxx) { log.error("[SEVERE] Unable to send exception report, error:", xxx); } }
From source file:com.gargoylesoftware.htmlunit.SimpleWebTestCase.java
/** * Cleanup after a test./*from w w w .ja v a2 s . co m*/ */ @After public void releaseResources() { super.releaseResources(); if (webClient_ != null) { webClient_.closeAllWindows(); webClient_.getCookieManager().clearCookies(); } webClient_ = null; final List<Thread> jsThreads = getJavaScriptThreads(); // collect stack traces // caution: the threads may terminate after the threads have been returned by getJavaScriptThreads() // and before stack traces are retrieved if (jsThreads.size() > nbJSThreadsBeforeTest_) { final Map<String, StackTraceElement[]> stackTraces = new HashMap<String, StackTraceElement[]>(); for (final Thread t : jsThreads) { final StackTraceElement elts[] = t.getStackTrace(); if (elts != null) { stackTraces.put(t.getName(), elts); } } if (!stackTraces.isEmpty()) { System.err.println("JS threads still running:"); for (final Map.Entry<String, StackTraceElement[]> entry : stackTraces.entrySet()) { System.err.println("Thread: " + entry.getKey()); final StackTraceElement elts[] = entry.getValue(); for (final StackTraceElement elt : elts) { System.err.println(elt); } } throw new RuntimeException("JS threads are still running: " + jsThreads.size()); } } }
From source file:net.darkmist.clf.IndexedLogFileHandler.java
/** Checks for index file and presence of the user in the index if it exists. * @param file The log file being examined * @param base The base name of the log file * @return true if the index file exists and the index file does NOT contain the user. *//*from w ww . j av a 2 s . c o m*/ private boolean notInIndex(File file, String base) { File dir; File index; InputStream in = null; String previousThreadName; Thread thread; int bufSize; if ((dir = file.getParentFile()) == null) { logger.warn("Log file " + file + " doesn't have a parent directory?"); return false; } index = new File(dir, base + INDEX_EXT); if (!index.exists()) { if (logger.isDebugEnabled()) logger.debug("no index file " + index + " for log file " + file); return false; } thread = Thread.currentThread(); previousThreadName = thread.getName(); thread.setName("idx: " + index); if (logger.isDebugEnabled()) logger.debug("index scan of " + index); bufSize = (int) Math.min(index.length(), MAX_BUF_SIZE); try { in = new GZIPInputStream(new BufferedInputStream(new FileInputStream(index), bufSize)); if (LineMatcher.readerContains(usrPat, new BufferedReader(new InputStreamReader(in)))) { logger.debug("found usr in index"); return false; } logger.debug("did not find usr in index"); return true; } catch (IOException e) { logger.warn("IOException reading from index " + index, e); } finally { in = Util.close(in, logger, index.toString()); thread.setName(previousThreadName); } return false; }
From source file:eu.stratosphere.nephele.services.iomanager.IOManager.java
@Override public void uncaughtException(Thread t, Throwable e) { LOG.fatal("IO Thread '" + t.getName() + "' terminated due to an exception. Closing I/O Manager.", e); shutdown();// w w w.ja v a 2s.c o m }
From source file:com.xpn.xwiki.monitor.api.MonitorPlugin.java
public void startRequest(String page, String action, URL url) { if (isActive() == false) return;/*from ww w .jav a 2 s . com*/ try { Thread cthread = Thread.currentThread(); MonitorData mdata = (MonitorData) activeTimerDataList.get(cthread); if (mdata != null) { removeFromActiveTimerDataList(cthread); addToLastUnfinishedTimerDataList(mdata); if (LOGGER.isDebugEnabled()) { LOGGER.debug("MONITOR: Thread " + cthread.getName() + " for page " + mdata.getWikiPage() + " did not call endRequest"); } mdata.endRequest(false); } mdata = new MonitorData(page, action, url, cthread.getName()); activeTimerDataList.put(cthread, mdata); } catch (Throwable e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("MONITOR: endRequest failed with exception " + e); e.printStackTrace(); } } }
From source file:edu.umass.cs.nio.JSONMessenger.java
/** * @param niot/*from w ww .j ava 2 s . c o m*/ * @param numWorkers */ @SuppressWarnings("unchecked") public JSONMessenger(final InterfaceNIOTransport<NodeIDType, JSONObject> niot, int numWorkers) { // to not create thread pools unnecessarily if (niot instanceof JSONMessenger) this.execpool = ((JSONMessenger<NodeIDType>) niot).execpool; else this.execpool = Executors.newScheduledThreadPool(5, new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread thread = Executors.defaultThreadFactory().newThread(r); thread.setName(JSONMessenger.class.getSimpleName() + niot.getMyID() + thread.getName()); return thread; } }); nioTransport = (InterfaceNIOTransport<NodeIDType, JSONObject>) niot; this.workers = new MessageNIOTransport[numWorkers]; for (int i = 0; i < workers.length; i++) { try { log.info((this + " starting worker with ssl mode " + this.nioTransport.getSSLMode())); this.workers[i] = new MessageNIOTransport<NodeIDType, JSONObject>(null, this.getNodeConfig(), this.nioTransport.getSSLMode()); this.workers[i].setName(JSONMessenger.class.getSimpleName() + niot.getMyID() + "_send_worker" + i); } catch (IOException e) { this.workers[i] = null; e.printStackTrace(); } } }