List of usage examples for java.lang ThreadLocal ThreadLocal
public ThreadLocal()
From source file:me.j360.dubbo.modules.util.text.HashUtil.java
private static ThreadLocal<MessageDigest> createThreadLocalMessageDigest(final String digest) { return new ThreadLocal<MessageDigest>() { @Override//from ww w . j a va2s . c om protected MessageDigest initialValue() { try { return MessageDigest.getInstance(digest); } catch (NoSuchAlgorithmException e) { throw new RuntimeException( "unexpected exception creating MessageDigest instance for [" + digest + "]", e); } } }; }
From source file:org.alloy.metal.state.ThreadLocalManager.java
public static <T> ThreadLocal<T> createThreadLocal(final Class<T> type, final boolean createInitialValue) { ThreadLocal<T> response = new ThreadLocal<T>() { @Override// w ww . java 2s. com protected T initialValue() { addThreadLocal(this); if (!createInitialValue) { return null; } try { return type.newInstance(); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } @Override public void set(T value) { super.set(value); } }; return response; }
From source file:org.ots.dns.NameStore.java
protected NameStore() { globalNames = Collections.synchronizedMap(new HashMap()); localThread = new ThreadLocal(); }
From source file:com.kylinolap.dict.DateStrDictionary.java
static SimpleDateFormat getDateFormat(String datePattern) { ThreadLocal<SimpleDateFormat> formatThreadLocal = threadLocalMap.get(datePattern); if (formatThreadLocal == null) { threadLocalMap.put(datePattern, formatThreadLocal = new ThreadLocal<SimpleDateFormat>()); }/*from w ww. j a v a 2s.c o m*/ SimpleDateFormat format = formatThreadLocal.get(); if (format == null) { format = new SimpleDateFormat(datePattern); format.setTimeZone(TimeZone.getTimeZone("GMT")); // NOTE: this must // be GMT to // calculate // epoch date // correctly formatThreadLocal.set(format); } return format; }
From source file:by.creepid.docsreporter.converter.OdfXhtmlConverterAdapter.java
@Override public void afterPropertiesSet() throws Exception { options = XHTMLOptions.create();/*from w w w . ja v a2s. com*/ observables = new ThreadLocal<ImageExtractObservable>(); }
From source file:ch.cyberduck.core.sftp.SFTPQuotaFeature.java
@Override public Space get() throws BackgroundException { final ThreadLocal<Space> quota = new ThreadLocal<Space>() { @Override/*ww w .j a v a2s . c o m*/ protected Space initialValue() { return new Space(0L, Long.MAX_VALUE); } }; final Path home = new SFTPHomeDirectoryService(session).find(); new SFTPCommandFeature(session).send(String.format("df -Pk %s | awk '{print $3, $4}'", home.getAbsolute()), new DisabledProgressListener(), new TranscriptListener() { @Override public void log(final Type request, final String output) { switch (request) { case response: final String[] numbers = StringUtils.split(output, ' '); if (numbers.length == 2) { try { quota.set(new Space(Long.valueOf(numbers[0]) * 1000L, Long.valueOf(numbers[1]) * 1000L)); } catch (NumberFormatException e) { log.warn(String.format("Ignore line %s", output)); } } else { log.warn(String.format("Ignore line %s", output)); } } } }); return quota.get(); }
From source file:com.myee.tarot.core.classloader.ThreadLocalManager.java
public static <T> ThreadLocal<T> createThreadLocal(final Class<T> type, final boolean createInitialValue) { ThreadLocal<T> response = new ThreadLocal<T>() { @Override//from w ww . j a v a 2s . co m protected T initialValue() { addThreadLocal(this); if (!createInitialValue) { return null; } try { return type.newInstance(); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } @Override public void set(T value) { super.get(); super.set(value); } }; return response; }
From source file:org.gflogger.log4j.Log4jLoggerServiceImpl.java
public Log4jLoggerServiceImpl(final LogLevel level) { this.level = level; this.entries = new ThreadLocal<Map<String, Log4jEntry>>() { @Override// w ww . j av a 2s.c o m protected Map<String, Log4jEntry> initialValue() { return new HashMap<>(); } }; BasicConfigurator.configure(); }
From source file:com.flipkart.flux.client.runtime.LocalContextTest.java
@Before public void setUp() throws Exception { tlStateMachineDef = new ThreadLocal<>(); tlMutableInteger = new ThreadLocal<>(); localContext = new LocalContext(tlStateMachineDef, tlMutableInteger, new ThreadLocal<>()); }
From source file:com.flipkart.flux.client.runtime.LocalContext.java
public LocalContext() { this(new ThreadLocal<>(), new ThreadLocal<>(), new ThreadLocal<>()); }