List of usage examples for java.lang Thread getName
public final String getName()
From source file:com.vodafone360.people.service.transport.http.HttpConnectionThread.java
public static void logV(String tag, String message) { if (Settings.ENABLED_TRANSPORT_TRACE) { Thread t = Thread.currentThread(); Log.v("(PROTOCOL)", tag + "[" + t.getName() + "]" + " : " + message); }// ww w . j a v a 2s. com }
From source file:org.shareok.data.kernel.api.services.ServiceUtil.java
public static Thread getThreadByName(String name) { for (Thread th : Thread.getAllStackTraces().keySet()) { String threadName = th.getName(); if (null != threadName && threadName.equals(name)) { return th; }//w ww.ja va 2s .c o m } return null; }
From source file:password.pwm.util.Helper.java
public static ThreadFactory makePwmThreadFactory(final String namePrefix, final boolean daemon) { return new ThreadFactory() { private final ThreadFactory realThreadFactory = Executors.defaultThreadFactory(); @Override// w ww.j av a2s .c om public Thread newThread(final Runnable r) { final Thread t = realThreadFactory.newThread(r); t.setDaemon(daemon); if (namePrefix != null) { final String newName = namePrefix + t.getName(); t.setName(newName); } return t; } }; }
From source file:com.vodafone360.people.service.transport.http.photouploadmanager.PhotoUploadManager.java
/** * logs./*from ww w . java2 s . c om*/ * @param tag input * @param message input */ public static void logI(final String tag, final String message) { if (Settings.ENABLED_TRANSPORT_TRACE) { Thread t = Thread.currentThread(); Log.i("(PROTOCOL)", tag + "[" + t.getName() + "]" + " : " + message); } }
From source file:pcgen.util.Logging.java
/** * List the current stack of all threads to STDOUT. *//*from ww w .j a va2 s . c o m*/ public static void reportAllThreads() { Map<Thread, StackTraceElement[]> allThreads = Thread.getAllStackTraces(); StringBuilder b = new StringBuilder(); for (Thread t : allThreads.keySet()) { b.append("Thread: "); b.append(t.getName()); b.append(", stacktrace:\n"); StackTraceElement[] traces = allThreads.get(t); for (StackTraceElement element : traces) { b.append(" "); b.append(element.toString()); b.append('\n'); } } System.out.println("==== Thread listing ===="); System.out.println(b); System.out.println("===== end listing ====="); }
From source file:com.strategicgains.docussandra.controller.perf.remote.mongo.MongoLoader.java
public static void loadMongoData(MongoClientURI uri, final int NUM_WORKERS, Database database, final int numDocs, final PerfTestParent clazz) { logger.info("------------Loading Data into: " + database.name() + " with MONGO!------------"); try {/*from w w w. java 2s .c om*/ try { MongoClient mongoClient = new MongoClient(uri); mongoClient.setWriteConcern(WriteConcern.MAJORITY); DB db = mongoClient.getDB(database.name()); final DBCollection coll = db.getCollection(database.name()); ArrayList<Thread> workers = new ArrayList<>(NUM_WORKERS + 1); int docsPerWorker = numDocs / NUM_WORKERS; try { List<Document> docs = clazz.getDocumentsFromFS(); ArrayList<List<Document>> documentQueues = new ArrayList<>(NUM_WORKERS + 1); int numDocsAssigned = 0; while ((numDocsAssigned + 1) < numDocs) { int start = numDocsAssigned; int end = numDocsAssigned + docsPerWorker; if (end > numDocs) { end = numDocs - 1; } documentQueues.add(new ArrayList(docs.subList(start, end))); numDocsAssigned = end; } for (final List<Document> queue : documentQueues) { workers.add(new Thread() { @Override public void run() { for (Document d : queue) { DBObject o = (DBObject) JSON.parse(d.object()); coll.save(o); } logger.info("Thread " + Thread.currentThread().getName() + " is done. It processed " + queue.size() + " documents."); } }); } } catch (UnsupportedOperationException e)//we can't read everything in at once { //all we need to do in this block is find a way to set "workers" for (int i = 0; i < NUM_WORKERS; i++) { workers.add(new Thread() { private final int chunk = (int) (Math.random() * 100) + 150;//pick a random chunk so we are not going back to the FS all at the same time and potentially causing a bottle neck @Override public void run() { ThreadLocal<Integer> counter = new ThreadLocal<>(); counter.set(new Integer(0)); try { List<Document> docs = clazz.getDocumentsFromFS(chunk);//grab a handful of documents while (docs.size() > 0) { for (Document d : docs)//process the documents we grabbed { DBObject o = (DBObject) JSON.parse(d.object()); coll.save(o); counter.set(counter.get() + 1); } docs = clazz.getDocumentsFromFS(chunk);//grab another handful of documents } logger.info("Thread " + Thread.currentThread().getName() + " is done. It processed " + counter.get() + " documents."); } catch (IOException | ParseException e) { logger.error("Couldn't read from document", e); } } }); } } long start = new Date().getTime(); //start your threads! for (Thread t : workers) { t.start(); } logger.info("All threads started, waiting for completion."); boolean allDone = false; boolean first = true; while (!allDone || first) { first = false; boolean done = true; for (Thread t : workers) { if (t.isAlive()) { done = false; logger.info("Thread " + t.getName() + " is still running."); break; } } if (done) { allDone = true; } else { logger.info("We still have workers running..."); try { Thread.sleep(10000); } catch (InterruptedException e) { } } } long end = new Date().getTime(); long miliseconds = end - start; double seconds = (double) miliseconds / 1000d; output.info("Done loading data using: " + NUM_WORKERS + ". Took: " + seconds + " seconds"); double tpms = (double) numDocs / (double) miliseconds; double tps = tpms * 1000; double transactionTime = (double) miliseconds / (double) numDocs; output.info(database.name() + " Mongo Average Transactions Per Second: " + tps); output.info( database.name() + " Mongo Average Transactions Time (in miliseconds): " + transactionTime); } catch (UnknownHostException e) { logger.error("Couldn't connect to Mongo Server", e); } } catch (IOException | ParseException e) { logger.error("Couldn't read data.", e); } }
From source file:org.jboss.dashboard.profiler.ThreadProfile.java
public static String printStackTrace(Thread t, int lines) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println("'" + t.getName() + "' '" + t.getState().toString() + "' "); StackTraceElement[] trace = t.getStackTrace(); for (int i = 0; i < trace.length && i < lines; i++) { pw.println("\tat " + trace[i]); }//w w w . j a v a 2s. c om return sw.toString(); }
From source file:com.vodafone360.people.service.transport.http.HttpConnectionThread.java
public static void logE(String tag, String message, Throwable error) { if (Settings.ENABLED_TRANSPORT_TRACE) { Thread t = Thread.currentThread(); if (null != error) { Log.e("(PROTOCOL)", "\n \n \n ################################################## \n" + tag + "[" + t.getName() + "]" + " : " + message, error); } else {// w w w . j a v a2s . c om Log.e("(PROTOCOL)", "\n \n \n ################################################## \n" + tag + "[" + t.getName() + "]" + " : " + message); } } if (null != error) { LogUtils.logE(message + " : " + error.toString()); } else { LogUtils.logE(message + " (Note: Settings.ENABLED_TRANSPORT_TRACE might give you more details!)"); } }
From source file:bear.core.BearMain.java
public static StringBuilder threadDump() { Map<Thread, StackTraceElement[]> map = Thread.getAllStackTraces(); StringBuilder sb = new StringBuilder(); for (Map.Entry<Thread, StackTraceElement[]> e : map.entrySet()) { Thread thread = e.getKey(); StackTraceElement[] elements = e.getValue(); StackTraceElement el = elements == null || elements.length == 0 ? null : elements[0]; sb.append(thread.getName()); if (el != null) { sb.append("\tat ").append(el).append("\n"); }/*from ww w. j a v a 2s . c o m*/ } sb.append("\n\n"); Exception e = new Exception(); for (Map.Entry<Thread, StackTraceElement[]> entry : map.entrySet()) { Thread thread = entry.getKey(); StackTraceElement[] stack = entry.getValue(); sb.append(thread.getName()).append(", id=").append(thread.getId()).append("\n"); e.setStackTrace(stack); sb.append(Throwables.getStackTraceAsString(e)); sb.append("\n"); } return sb; }
From source file:org.openmrs.util.OpenmrsClassLoader.java
private static List<Thread> listThreads(ThreadGroup group, String indent) { List<Thread> threadToReturn = new ArrayList<Thread>(); log.error(indent + "Group[" + group.getName() + ":" + group.getClass() + "]"); int nt = group.activeCount(); Thread[] threads = new Thread[nt * 2 + 10]; //nt is not accurate nt = group.enumerate(threads, false); // List every thread in the group for (int i = 0; i < nt; i++) { Thread t = threads[i]; log.error(indent + " Thread[" + t.getName() + ":" + t.getClass() + ":" + (t.getContextClassLoader() == null ? "null cl" : t.getContextClassLoader().getClass().getName() + " " + t.getContextClassLoader().hashCode()) + "]"); threadToReturn.add(t);//from w w w. jav a 2 s .c o m } // Recursively list all subgroups int ng = group.activeGroupCount(); ThreadGroup[] groups = new ThreadGroup[ng * 2 + 10]; ng = group.enumerate(groups, false); for (int i = 0; i < ng; i++) { threadToReturn.addAll(listThreads(groups[i], indent + " ")); } return threadToReturn; }