List of usage examples for java.lang Thread currentThread
@HotSpotIntrinsicCandidate public static native Thread currentThread();
From source file:PropertyLoader.java
public static Properties loadProperties(final String name) throws Exception { return loadProperties(name, Thread.currentThread().getContextClassLoader()); }
From source file:com.germinus.easyconf.ClasspathUtil.java
/** * Return the Class object of the specified class name by searching the * current classpath and the system classpath. * * @param name the name of the class//from ww w . j av a 2 s .co m * * @return the <code>Class</code> instance */ public static Class locateClass(String name) throws ClassNotFoundException { Class foundClass = null; if (foundClass == null) { ClassLoader loader = Thread.currentThread().getContextClassLoader(); try { foundClass = loader.loadClass(name); log.debug("Class loaded from the context classpath (" + name + ")"); } catch (ClassNotFoundException ignore) { } } if (foundClass == null) { try { foundClass = ClassLoader.getSystemClassLoader().loadClass(name); log.debug("Class loaded from the system classpath (" + name + ")"); } catch (ClassNotFoundException ignore) { } } if (foundClass == null) { throw new ClassNotFoundException( "Class " + name + " was not found " + "in context classpath nor system classpath"); } return foundClass; }
From source file:A.java
synchronized void bar(A a) { String name = Thread.currentThread().getName(); System.out.println(name + " entered B.bar"); try {//from w w w . j ava 2s .c o m Thread.sleep(1000); } catch (Exception e) { System.out.println("B Interrupted"); } System.out.println(name + " trying to call A.last()"); a.last(); }
From source file:Main.java
/** * Workaround for Java problem on Windows with releasing buffers for memory-mapped files. * * @see "http://stackoverflow.com/questions/3602783/file-access-synchronized-on-java-object" * @see "http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6354433" * @see "http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4715154" * @see "http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4469299" *//*from w w w. j a v a 2s. c o m*/ private static FileOutputStream getFileOutputStreamWorkaround(java.io.File storeFile) throws FileNotFoundException { final int maxCount = 10; for (int i = 0; i <= maxCount; i++) { try { // there is no sleep on first round Thread.sleep(10 * i); } catch (InterruptedException e) { // restore interrupted status Thread.currentThread().interrupt(); } try { return new FileOutputStream(storeFile); } catch (FileNotFoundException e) { // only apply workaround for the very specific exception if (i >= maxCount || !e.getMessage().contains( "The requested operation cannot be performed on a file with a user-mapped section open")) { //$NON-NLS-1$ throw e; } // CCorePlugin.log(new Status(IStatus.INFO, CCorePlugin.PLUGIN_ID, "Workaround for concurrent access to memory-mapped files applied, attempt " + (i + 1), e)); //$NON-NLS-1$ } } // will never get here return null; }
From source file:ClassLoaderUtils.java
/** * Load a given resource.//from w w w . j a v a2s . c om * <p/> * This method will try to load the resource using the following methods (in order): * <ul> * <li>From {@link Thread#getContextClassLoader() Thread.currentThread().getContextClassLoader()} * <li>From {@link Class#getClassLoader() ClassLoaderUtil.class.getClassLoader()} * <li>From the {@link Class#getClassLoader() callingClass.getClassLoader() } * </ul> * * @param resourceName The name of the resource to load * @param callingClass The Class object of the calling object */ public static URL getResource(String resourceName, Class callingClass) { URL url = null; url = Thread.currentThread().getContextClassLoader().getResource(resourceName); if (url == null) { url = ClassLoaderUtils.class.getClassLoader().getResource(resourceName); } if (url == null) { url = callingClass.getClassLoader().getResource(resourceName); } return url; }
From source file:Main.java
public static ThreadFactory createFactory(final String threadName) { return new ThreadFactory() { int sequence; public Thread newThread(Runnable r) { sequence += 1;/*from w w w .j a v a 2s . c o m*/ StringBuilder sb = new StringBuilder(); sb.append('[').append(Thread.currentThread().getThreadGroup().getName()).append("] "); sb.append(threadName).append(" - ").append(sequence); return new Thread(r, sb.toString()); } }; }
From source file:Main.java
@Override public void run() { while (true) { System.out.println("inside mail Consumer"); System.out.println("Thread executing = " + Thread.currentThread().getName()); }/*from www . j av a 2 s .c o m*/ }
From source file:de.erdesignerng.util.JasperUtils.java
private static void findReports(Map<File, String> aReportMap, File aDirectory) throws JRException { Thread.currentThread().setContextClassLoader(JasperUtils.class.getClassLoader()); if (aDirectory != null && aDirectory.exists() && aDirectory.canRead()) { for (File theFile : aDirectory.listFiles()) { String theName = theFile.getName(); if (theName.endsWith(".jrxml") && (!theName.contains("_"))) { try { JasperDesign theDesign = JRXmlLoader.load(new FileInputStream(theFile)); String theReportName = theDesign.getName(); if (StringUtils.isNotEmpty(theReportName)) { aReportMap.put(theFile, theReportName); }/*from ww w.j a va 2 s. com*/ } catch (FileNotFoundException e) { // This cannot happen } } else { if ((theFile.isDirectory()) && (!".".equals(theName)) && (!"..".equals(theName))) { findReports(aReportMap, theFile); } } } } }
From source file:com.univocity.articles.kairosdb.KairosDbLoadProcess.java
public static void main(String... args) { new Thread() { // this is just a quick and dirty example, you should use a proper task scheduler @Override/* ww w . j a v a 2 s . c o m*/ public void run() { KairosDbLoadProcess process = null; try { process = new KairosDbLoadProcess(); while (true) { process.execute(); try { Thread.sleep(3000); //let's pull 1000 rows every 3 seconds. } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } } finally { if (process != null) { process.shutdown(); } } } }.start(); }
From source file:com.cloudera.sqoop.util.ClassLoaderStack.java
/** * Sets the classloader for the current thread. *//* www.j a v a 2 s . co m*/ public static void setCurrentClassLoader(ClassLoader cl) { LOG.debug("Restoring classloader: " + cl.toString()); Thread.currentThread().setContextClassLoader(cl); }