List of usage examples for java.lang Thread currentThread
@HotSpotIntrinsicCandidate public static native Thread currentThread();
From source file:net.erdfelt.android.sdkfido.Build.java
public static String getVersion() { if (version == null) { ClassLoader cl = Thread.currentThread().getContextClassLoader(); String resource = String.format("META-INF/maven/%s/%s/pom.properties", GROUP_ID, ARTIFACT_ID); URL url = cl.getResource(resource); if (url == null) { version = "[DEV]"; } else {/* w w w. ja v a 2s. co m*/ InputStream in = null; try { in = url.openStream(); Properties props = new Properties(); props.load(in); version = props.getProperty("version"); } catch (IOException e) { LOG.log(Level.WARNING, "Unable to read: " + url, e); version = "[UNKNOWN]"; } finally { IOUtils.closeQuietly(in); } } } return version; }
From source file:Main.java
public void read() { while (true) { rwl.readLock().lock();//from w w w . j a v a 2 s. co m try { System.out.println("Counter is " + counter); } finally { rwl.readLock().unlock(); } try { Thread.currentThread().sleep(1000); } catch (Exception ie) { } } }
From source file:com.taobao.pushit.commons.ClientLoggerInit.java
public static void initLog() { if (initOK) { return;/* www .j a v a 2 s . c o m*/ } URL url = null; ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl == null || (url = cl.getResource(PUSHIT_CLIENT_LOG4J_FILE)) == null) { cl = ClientLoggerInit.class.getClassLoader(); if (cl == null || (url = cl.getResource(PUSHIT_CLIENT_LOG4J_FILE)) == null) { fallback(); return; } } final ClassLoader pre = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(PropertyConfigurator.class.getClassLoader()); PropertyConfigurator.configure(url); } finally { Thread.currentThread().setContextClassLoader(pre); } // root loggerfile appender, appenderpushit.log FileAppender rootFileAppender = getFileAppender(Logger.getRootLogger()); if (rootFileAppender == null) { log.warn("root loggerfile appender!!!"); rootFileAppender = new FileAppender(); rootFileAppender.setFile(System.getProperty("user.home") + "/diamond/logs/pushit-client.log"); } // pushit logger, log4jappenderlogger, // geckopushitappender setFileAppender(rootFileAppender, PUSHIT_CLIENT_LOGGER); initOK = true; }
From source file:org.apache.kylin.jdbc.TestUtil.java
public static String getResourceContent(String path) { ClassLoader loader = Thread.currentThread().getContextClassLoader(); StringWriter writer = new StringWriter(); InputStream is = loader.getResourceAsStream(path); if (is == null) { throw new IllegalArgumentException(new FileNotFoundException(path + " not found in class path")); }//from w ww . jav a2s . com try { IOUtils.copy(is, writer, "utf-8"); return writer.toString(); } catch (IOException e) { IOUtils.closeQuietly(is); throw new RuntimeException(e); } }
From source file:Main.java
public void run() { System.out.println(Thread.currentThread().getName() + " " + i); }
From source file:ThreadUtil.java
/** * Get the string ID for the current thread. * /*from w ww .j a va2 s .co m*/ * @return The thread id */ public static String getThreadId() { return getThreadId(Thread.currentThread()); }
From source file:eu.riscoss.RemoteRiskAnalyserMain.java
static void loadJSmile() throws Exception { File dir = new File(FileUtils.getTempDirectory(), "jnativelibs-" + RandomStringUtils.randomAlphabetic(30)); if (!dir.mkdir()) { throw new Exception("failed to make dir"); }/*from w ww . jav a 2 s . com*/ File jsmile = new File(dir, "libjsmile.so"); URL jsmURL = Thread.currentThread().getContextClassLoader().getResource("libjsmile.so"); FileUtils.copyURLToFile(jsmURL, jsmile); System.setProperty("java.library.path", System.getProperty("java.library.path") + ":" + dir.getAbsolutePath()); // flush the library paths Field sysPathsField = ClassLoader.class.getDeclaredField("sys_paths"); sysPathsField.setAccessible(true); sysPathsField.set(null, null); // Check that it works... System.loadLibrary("jsmile"); dir.deleteOnExit(); jsmile.deleteOnExit(); }
From source file:SecuritySupport.java
static ClassLoader getContextClassLoader() { return (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() { public Object run() { ClassLoader cl = null; try { cl = Thread.currentThread().getContextClassLoader(); } catch (SecurityException ex) { }//from ww w. j a v a2s . com return cl; } }); }
From source file:com.dtolabs.client.utils.ClientState.java
/** * Get the HTTP State object for the current thread *///from w w w.j a v a 2 s. com public synchronized static HttpState getHttpState() { return getState(Thread.currentThread()); }
From source file:com.lewisd.maven.lint.rules.opensource.OpensourceRulesIT.java
@BeforeClass public static void beforeAllTest() { applicationContext = new GenericApplicationContext(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); ClassPathResource classPathResource = new ClassPathResource(CONFIG_LOCATION, classLoader); XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(applicationContext); xmlBeanDefinitionReader.loadBeanDefinitions(classPathResource); applicationContext.getBeanFactory().registerSingleton("LOG", LOG); applicationContext.getBeanFactory().registerResolvableDependency(PluginParameterExpressionEvaluator.class, mock(PluginParameterExpressionEvaluator.class)); applicationContext.refresh();/* w w w . j a v a 2s. c o m*/ }