當前位置: 首頁>>代碼示例>>Java>>正文


Java NamedThreadLocal類代碼示例

本文整理匯總了Java中org.springframework.core.NamedThreadLocal的典型用法代碼示例。如果您正苦於以下問題:Java NamedThreadLocal類的具體用法?Java NamedThreadLocal怎麽用?Java NamedThreadLocal使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


NamedThreadLocal類屬於org.springframework.core包,在下文中一共展示了NamedThreadLocal類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: get

import org.springframework.core.NamedThreadLocal; //導入依賴的package包/類
@Override
public Object get(String name, ObjectFactory<?> objectFactory) {
  try {
    Object mutex = RequestContextHolder.currentRequestAttributes().getSessionMutex();
    synchronized (mutex) {
      return super.get(name, objectFactory);
    }
  } catch (IllegalStateException e) {
    logger.debug("outside web session");
    ThreadLocal<Object> objectHolder = objectHolders.get(name);
    if (objectHolder == null) {
      objectHolders.put(name, new NamedThreadLocal<>("wideScopeObjectHolder_" + name));
      objectHolder = objectHolders.get(name);
    }

    if (objectHolder.get() == null) {
      objectHolder.set(objectFactory.getObject());
    }
    return objectHolder.get();
  }
}
 
開發者ID:tunguski,項目名稱:matsuo-core,代碼行數:22,代碼來源:WideSessionScope.java

示例2: test

import org.springframework.core.NamedThreadLocal; //導入依賴的package包/類
@Test
public void test(){
    final ThreadLocal<Object> prototypesCurrentlyInCreation =
            new NamedThreadLocal<Object>("Prototype beans currently in creation");

    Assert.assertNull(prototypesCurrentlyInCreation.get());
    prototypesCurrentlyInCreation.set("abc");
    Assert.assertNotNull(prototypesCurrentlyInCreation.get());
    prototypesCurrentlyInCreation.set(new HashSet<String>());
    Assert.assertNotNull(prototypesCurrentlyInCreation.get());
    prototypesCurrentlyInCreation.remove();
    Assert.assertNull(prototypesCurrentlyInCreation.get());
    System.out.println(prototypesCurrentlyInCreation.toString());
}
 
開發者ID:whyDK37,項目名稱:pinenut,代碼行數:15,代碼來源:ThreadLocalTest.java


注:本文中的org.springframework.core.NamedThreadLocal類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。