List of usage examples for java.lang Thread currentThread
@HotSpotIntrinsicCandidate public static native Thread currentThread();
From source file:de.micromata.genome.gwiki.utils.ScriptUtils.java
public static Object executeScriptCode(String code, Map<String, Object> vars) { if (StringUtils.isBlank(code) == true) { return null; }/*from www . j a v a 2 s .c o m*/ GroovyClassLoader loader = new GroovyClassLoader(Thread.currentThread().getContextClassLoader()); Binding binding = new Binding(vars); GroovyShell shell = new GroovyShell(loader, binding); return shell.evaluate(code); }
From source file:com.github.nukesparrow.htmlunit.Util.java
public static MapBuilder mapBuilderBaseData() { MapBuilder b = new MapBuilder().put("time", System.currentTimeMillis()); StringBuilder sb = new StringBuilder(); for (StackTraceElement e : Thread.currentThread().getStackTrace()) { sb.append(e.toString()).append('\n'); }//from w w w . ja v a 2s . co m b.put("stack", sb.toString()); return b; }
From source file:Main.java
/** * Determines the name of the invoking method.<br /> * <br />/*w w w. ja va 2s.c o m*/ * <i><u>Note:</u><br /> * The method looks for the method name within the current thread's stack trace. The * current implementation looks for the name at a fixed position.</i> * * @return a method name */ public static String getMethodName() { Thread currentThread = Thread.currentThread(); StackTraceElement[] stackTrace = currentThread.getStackTrace(); int elements = stackTrace.length; int expectedIndex = 3; if (expectedIndex < elements) { StackTraceElement element = stackTrace[expectedIndex]; String[] substrings = element.toString().split("\\("); String name = substrings[0]; return name; } return "unknown method"; }
From source file:de.micromata.genome.gwiki.utils.ClassUtils.java
public static Class<?> classForName(String className) { ClassLoader cl = Thread.currentThread().getContextClassLoader(); try {/* ww w. j a v a2 s . co m*/ return Class.forName(className, true, cl); } catch (Throwable ex) { try { Class.forName(className, true, cl); } catch (Exception ex2) { } throw new RuntimeException("Failed to load class: " + className + "; " + ex.getMessage(), ex); } }
From source file:Main.java
public void run() { Thread t = Thread.currentThread(); System.out.print(t.getName()); // checks if this thread is alive System.out.println(", status = " + t.isAlive()); }
From source file:Main.java
public void run() { Thread t = Thread.currentThread(); System.out.print(t.getName()); System.out.println(", status = " + t.isAlive()); }
From source file:Main.java
/** * Same as {@link Thread#sleep(long)} except Exception is caught and ignored. *///w w w . j av a2 s. c o m public static void sleep(int milli) { try { Thread.sleep(milli); } catch (InterruptedException e) { // have to interrupt the thread Thread.currentThread().interrupt(); } }
From source file:net.dovemq.transport.link.LinkTestUtils.java
public static void sendMessagesOnLink(CAMQPLinkSender linkSender, int numMessagesToSend) { Random randomGenerator = new Random(); for (int i = 0; i < numMessagesToSend; i++) { int randomInt = randomGenerator.nextInt(5); CAMQPMessage message = createMessage(randomGenerator); linkSender.sendMessage(new CAMQPMessage(message.getDeliveryTag(), message.getPayload())); try {//from w w w . j a va 2 s. co m Thread.sleep(randomInt); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } }
From source file:ThreadLister.java
/** Find the root thread group and list it recursively */ public static void listAllThreads() { ThreadGroup currentThreadGroup; ThreadGroup rootThreadGroup;//www . j av a 2 s. co m ThreadGroup parent; // Get the current thread group currentThreadGroup = Thread.currentThread().getThreadGroup(); // Now go find the root thread group rootThreadGroup = currentThreadGroup; parent = rootThreadGroup.getParent(); while (parent != null) { rootThreadGroup = parent; parent = parent.getParent(); } printGroupInfo(rootThreadGroup, ""); }
From source file:jp.co.cyberagent.parquet.msgpack.CSVAsJSONIterator.java
public static CSVAsJSONIterator fromResource(String name, CSVFormat format, CSVHeaderMap headerMap) { File file = new File(Thread.currentThread().getContextClassLoader().getResource(name).getPath()); return new CSVAsJSONIterator(file, format, headerMap); }