/** * Used internally by CGLIB. Returns the <code>AbstractClassGenerator</code> * that is being used to generate a class in the current thread. */ public static AbstractClassGenerator getCurrent() { return (AbstractClassGenerator) CURRENT.get(); }
@Override public Kryo getKryo() { return holder.get(); } }
/** * Return the LocaleContext associated with the current thread, if any. * @return the current LocaleContext, or {@code null} if none */ @Nullable public static LocaleContext getLocaleContext() { LocaleContext localeContext = localeContextHolder.get(); if (localeContext == null) { localeContext = inheritableLocaleContextHolder.get(); } return localeContext; }
/** * Return the name of the currently proxied bean instance. * @return the name of the bean, or {@code null} if none available */ @Nullable public static String getCurrentProxiedBeanName() { return currentProxiedBeanName.get(); }
/** * Return the JodaTimeContext associated with the current thread, if any. * @return the current JodaTimeContext, or {@code null} if none */ @Nullable public static JodaTimeContext getJodaTimeContext() { return jodaTimeContextHolder.get(); }
/** * Return the {@link ResourceLoader} for the currently configured Quartz Scheduler, * to be used by {@link ResourceLoaderClassLoadHelper}. * <p>This instance will be set before initialization of the corresponding Scheduler, * and reset immediately afterwards. It is thus only available during configuration. * @see #setApplicationContext * @see ResourceLoaderClassLoadHelper */ @Nullable public static ResourceLoader getConfigTimeResourceLoader() { return configTimeResourceLoaderHolder.get(); }
private void bindToThread() { // Expose current TransactionStatus, preserving any existing TransactionStatus // for restoration after this transaction is complete. this.oldTransactionInfo = transactionInfoHolder.get(); transactionInfoHolder.set(this); }
/** * Return the name of the current transaction, or {@code null} if none set. * To be called by resource management code for optimizations per use case, * for example to optimize fetch strategies for specific named transactions. * @see org.springframework.transaction.TransactionDefinition#getName() */ @Nullable public static String getCurrentTransactionName() { return currentTransactionName.get(); }
/** * Return the SimpAttributes currently bound to the thread. * @return the attributes or {@code null} if not bound */ @Nullable public static SimpAttributes getAttributes() { return attributesHolder.get(); }
/** * Return the DateTimeContext associated with the current thread, if any. * @return the current DateTimeContext, or {@code null} if none */ @Nullable public static DateTimeContext getDateTimeContext() { return dateTimeContextHolder.get(); }
@Nullable static TransactionContext removeCurrentTransactionContext() { TransactionContext transactionContext = currentTransactionContext.get(); currentTransactionContext.remove(); return transactionContext; }
/** * Return whether the specified prototype bean is currently in creation * (within the current thread). * @param beanName the name of the bean */ protected boolean isPrototypeCurrentlyInCreation(String beanName) { Object curVal = this.prototypesCurrentlyInCreation.get(); return (curVal != null && (curVal.equals(beanName) || (curVal instanceof Set && ((Set<?>) curVal).contains(beanName)))); }
@Override public Object get(String name, ObjectFactory<?> objectFactory) { Map<String, Object> scope = this.threadScope.get(); Object scopedObject = scope.get(name); if (scopedObject == null) { scopedObject = objectFactory.getObject(); scope.put(name, scopedObject); } return scopedObject; }
private static int getNonGoldenRandomKey() { int key; do { key = random.get().nextInt(); } while (key == GOLDEN_PRESENT_KEY); return key; } }
@Override public void run() { threadLocalCount.set(threadLocalCount.get() + 1); } };
@Override public Integer call() { int i = threadLocalCount.get(); threadLocalCount.set(i + 1); return i; } };
/** * CycleDetectingLock implementations must call this method before attempting to acquire the lock. */ private void aboutToAcquire(CycleDetectingLock lock) { if (!lock.isAcquiredByCurrentThread()) { ArrayList<LockGraphNode> acquiredLockList = acquiredLocks.get(); LockGraphNode node = lock.getLockGraphNode(); node.checkAcquiredLocks(policy, acquiredLockList); acquiredLockList.add(node); } }
@Override public void run() { try { Future<?> future = executor.submit(incrementTask); assertTrue(future.isDone()); assertEquals(1, threadLocalCount.get().intValue()); } catch (Throwable t) { throwableFromOtherThread.set(t); } } });