在路上

 找回密码
 立即注册
在路上 站点首页 学习 查看内容

清理ThreadLocal

2017-2-9 13:07| 发布者: zhangjf| 查看: 655| 评论: 0

摘要: 在我很多的课程里(master、concurrency、xj-conc-j8),我经常提起ThreadLocal。它经常受到我严厉的指责要尽可能的避免使用。ThreadLocal是为了那些使用完就销毁的线程设计的。线程生成之前,线程内的局部变量都会 ...

在我很多的课程里(master、concurrency、xj-conc-j8),我经常提起ThreadLocal。它经常受到我严厉的指责要尽可能的避免使用。ThreadLocal是为了那些使用完就销毁的线程设计的。线程生成之前,线程内的局部变量都会被清除掉。实际上,如果你读过 Why 0x61c88647?,这篇文章中解释了实际的值是存在一个内部的map中,这个map是伴随着线程的产生而产生的。存在于线程池的线程不会只存活于单个用户请求,这很容易导致内存溢出。通常我在讨论这个的时候,至少有一位学生有过因为在一个线程局部变量持有某个类而导致整个生产系统奔溃。因此,预防实体类加载后不被卸载,是一个非常普遍的问题。

在这篇文章中,我将演示一个ThreadLocalCleaner类。通过这个类,可以在线程回到线程池之前,恢复所有本地线程变量到最开始的状态。最基础的,我们可以保存当前线程的ThreadLocal的状态,之后再重置。我们可以使用Java 7提供的try-with-resource结构来完成这件事情。例如:

  1. try (ThreadLocalCleaner tlc = new ThreadLocalCleaner()) {
  2. // some code that potentially creates and adds thread locals
  3. }
  4. // at this point, the new thread locals have been cleared
复制代码

为了简化调试,我们增加一个观察者的机制,这样我们能够监测到线程局部map发生的任何变化。这能帮助我们发现可能出现泄漏的线程局部变量。这是我们的监听器:

  1. package threadcleaner;
  2. @FunctionalInterface
  3. public interface ThreadLocalChangeListener {
  4. void changed(Mode mode, Thread thread,
  5. ThreadLocal<?> threadLocal, Object value);
  6. ThreadLocalChangeListener EMPTY = (m, t, tl, v) -> {};
  7. ThreadLocalChangeListener PRINTER =
  8. (m, t, tl, v) -> System.out.printf(
  9. "Thread %s %s ThreadLocal %s with value %s%n",
  10. t, m, tl.getClass(), v);
  11. enum Mode {
  12. ADDED, REMOVED
  13. }
  14. }
复制代码

这个地方可能需要做一下必要的说明。首先,我添加了注解@FunctionalInterface,这个注解是Java 8提供的,它的意思是该类只有一个抽象方法,可以作为lambda表达式使用。其次,我在该类的内部定义了一个EMPTY的lambda表达式。这样,你可以见识到,这段代码会非常短小。第三,我还定义了一个默认的PRINTER,它可以简单的通过System.out输出改变的信息。最后,我们还有两个不不同的事件,但是因为想设计成为一个函数式编程接口(@FunctionalInterface),我不得不把这个标示定义为单独的属性,这里定义成了枚举。

当我们构造ThreadLocalCleaner时,我们可以传递一个ThreadLocalChangeListener。这样,从Treadlocal创建开始发生的任何变化,我们都能监测到。请注意,这种机制只适合于当前线程。这有一个例子演示我们怎样通过try-with-resource代码块来使用ThreadLocalCleaner:任何定义在在 try(…) 中的局部变量,都会在代码块的自后进行自动关闭。因此,我们需要在ThreadLocalCleaner内部有一个 close() 方法,用于恢复线程局部变量到初始值。

  1. import java.text.*;
  2. public class ThreadLocalCleanerExample {
  3. private static final ThreadLocal df =
  4. new ThreadLocal() {
  5. protected DateFormat initialValue() {
  6. return new SimpleDateFormat("yyyy-MM-dd");
  7. }
  8. };
  9. public static void main(String... args) {
  10. System.out.println("First ThreadLocalCleaner context");
  11. try (ThreadLocalCleaner tlc = new ThreadLocalCleaner(
  12. ThreadLocalChangeListener.PRINTER)) {
  13. System.out.println(System.identityHashCode(df.get()));
  14. System.out.println(System.identityHashCode(df.get()));
  15. System.out.println(System.identityHashCode(df.get()));
  16. }
  17. System.out.println("Another ThreadLocalCleaner context");
  18. try (ThreadLocalCleaner tlc = new ThreadLocalCleaner(
  19. ThreadLocalChangeListener.PRINTER)) {
  20. System.out.println(System.identityHashCode(df.get()));
  21. System.out.println(System.identityHashCode(df.get()));
  22. System.out.println(System.identityHashCode(df.get()));
  23. }
  24. }
  25. }
复制代码

在ThreadLocalCleaner类中还有两个公共的静态方法:forEach() 和 cleanup(Thread)。forEach() 方法有两个参数:Thread和BiConsumer。该方法通过ThreadLocal调用来遍历其中的每一个值。我们跳过了key为null的对象,但是没有跳过值为null的对象。理由是如果仅仅是值为null,ThreadLocal仍然有可能出现内存泄露。一旦我们使用完了ThreadLocal,就应该在将线程返回给线程池之前调用 remove() 方法。cleanup(Thread) 方法设置ThreadLocal的map在该线程内为null,因此,允许垃圾回收器回收所有的对象。如果一个ThreadLocal在我们清理后再次使用,就简单的调用 initialValue() 方法来创建对象。这是方法的定义:

  1. public static void forEach(Thread thread,
  2. BiConsumer<ThreadLocal<?>, Object> consumer) { ... }
  3. public static void cleanup(Thread thread) { ... }
复制代码

ThreadLocalCleaner类完整的代码如下。该类使用了许多反射来操作私有域。它可能只能在OpenJDK或其直接衍生产品上运行。你也能注意到我使用了Java 8的语法。我纠结过很长一段时间是否使用Java 8 或 7。我的某些客户端还在使用1.4。最后,我的大部分大银行客户已经在产品中开始使用Java 8。银行通常来说不是最先采用的新技术人,除非存在非常大的经济意义。因此,如果你还没有在产品中使用Java 8,你应该尽可能快的移植过去,甚至可以跳过Java 8,直接到Java 9。你应该可以很容易的反向移植到Java 7上,只需要自定义一个BiConsumer接口。Java 6不支持try-with-resource结构,所以反向移植会比较困难一点。

  1. package threadcleaner;
  2. import java.lang.ref.*;
  3. import java.lang.reflect.*;
  4. import java.util.*;
  5. import java.util.function.*;
  6. import static threadcleaner.ThreadLocalChangeListener.Mode.*;
  7. public class ThreadLocalCleaner implements AutoCloseable {
  8. private final ThreadLocalChangeListener listener;
  9. public ThreadLocalCleaner() {
  10. this(ThreadLocalChangeListener.EMPTY);
  11. }
  12. public ThreadLocalCleaner(ThreadLocalChangeListener listener) {
  13. this.listener = listener;
  14. saveOldThreadLocals();
  15. }
  16. public void close() {
  17. cleanup();
  18. }
  19. public void cleanup() {
  20. diff(threadLocalsField, copyOfThreadLocals.get());
  21. diff(inheritableThreadLocalsField,
  22. copyOfInheritableThreadLocals.get());
  23. restoreOldThreadLocals();
  24. }
  25. public static void forEach(
  26. Thread thread,
  27. BiConsumer<ThreadLocal<?>, Object> consumer) {
  28. forEach(thread, threadLocalsField, consumer);
  29. forEach(thread, inheritableThreadLocalsField, consumer);
  30. }
  31. public static void cleanup(Thread thread) {
  32. try {
  33. threadLocalsField.set(thread, null);
  34. inheritableThreadLocalsField.set(thread, null);
  35. } catch (IllegalAccessException e) {
  36. throw new IllegalStateException(
  37. "Could not clear thread locals: " + e);
  38. }
  39. }
  40. private void diff(Field field, Reference<?>[] backup) {
  41. try {
  42. Thread thread = Thread.currentThread();
  43. Object threadLocals = field.get(thread);
  44. if (threadLocals == null) {
  45. if (backup != null) {
  46. for (Reference<?> reference : backup) {
  47. changed(thread, reference,
  48. REMOVED);
  49. }
  50. }
  51. return;
  52. }
  53. Reference<?>[] current =
  54. (Reference<?>[]) tableField.get(threadLocals);
  55. if (backup == null) {
  56. for (Reference<?> reference : current) {
  57. changed(thread, reference, ADDED);
  58. }
  59. } else {
  60. // nested loop - both arrays *should* be relatively small
  61. next:
  62. for (Reference<?> curRef : current) {
  63. if (curRef != null) {
  64. if (curRef.get() == copyOfThreadLocals ||
  65. curRef.get() == copyOfInheritableThreadLocals) {
  66. continue next;
  67. }
  68. for (Reference<?> backupRef : backup) {
  69. if (curRef == backupRef) continue next;
  70. }
  71. // could not find it in backup - added
  72. changed(thread, curRef, ADDED);
  73. }
  74. }
  75. next:
  76. for (Reference<?> backupRef : backup) {
  77. for (Reference<?> curRef : current) {
  78. if (curRef == backupRef) continue next;
  79. }
  80. // could not find it in current - removed
  81. changed(thread, backupRef,
  82. REMOVED);
  83. }
  84. }
  85. } catch (IllegalAccessException e) {
  86. throw new IllegalStateException("Access denied", e);
  87. }
  88. }
  89. private void changed(Thread thread, Reference<?> reference,
  90. ThreadLocalChangeListener.Mode mode)
  91. throws IllegalAccessException {
  92. listener.changed(mode,
  93. thread, (ThreadLocal<?>) reference.get(),
  94. threadLocalEntryValueField.get(reference));
  95. }
  96. private static Field field(Class<?> c, String name)
  97. throws NoSuchFieldException {
  98. Field field = c.getDeclaredField(name);
  99. field.setAccessible(true);
  100. return field;
  101. }
  102. private static Class<?> inner(Class<?> clazz, String name) {
  103. for (Class<?> c : clazz.getDeclaredClasses()) {
  104. if (c.getSimpleName().equals(name)) {
  105. return c;
  106. }
  107. }
  108. throw new IllegalStateException(
  109. "Could not find inner class " + name + " in " + clazz);
  110. }
  111. private static void forEach(
  112. Thread thread, Field field,
  113. BiConsumer<ThreadLocal<?>, Object> consumer) {
  114. try {
  115. Object threadLocals = field.get(thread);
  116. if (threadLocals != null) {
  117. Reference<?>[] table = (Reference<?>[])
  118. tableField.get(threadLocals);
  119. for (Reference<?> ref : table) {
  120. if (ref != null) {
  121. ThreadLocal<?> key = (ThreadLocal<?>) ref.get();
  122. if (key != null) {
  123. Object value = threadLocalEntryValueField.get(ref);
  124. consumer.accept(key, value);
  125. }
  126. }
  127. }
  128. }
  129. } catch (IllegalAccessException e) {
  130. throw new IllegalStateException(e);
  131. }
  132. }
  133. private static final ThreadLocal<Reference<?>[]>
  134. copyOfThreadLocals = new ThreadLocal<>();
  135. private static final ThreadLocal<Reference<?>[]>
  136. copyOfInheritableThreadLocals = new ThreadLocal<>();
  137. private static void saveOldThreadLocals() {
  138. copyOfThreadLocals.set(copy(threadLocalsField));
  139. copyOfInheritableThreadLocals.set(
  140. copy(inheritableThreadLocalsField));
  141. }
  142. private static Reference<?>[] copy(Field field) {
  143. try {
  144. Thread thread = Thread.currentThread();
  145. Object threadLocals = field.get(thread);
  146. if (threadLocals == null) return null;
  147. Reference<?>[] table =
  148. (Reference<?>[]) tableField.get(threadLocals);
  149. return Arrays.copyOf(table, table.length);
  150. } catch (IllegalAccessException e) {
  151. throw new IllegalStateException("Access denied", e);
  152. }
  153. }
  154. private static void restoreOldThreadLocals() {
  155. try {
  156. restore(threadLocalsField, copyOfThreadLocals.get());
  157. restore(inheritableThreadLocalsField,
  158. copyOfInheritableThreadLocals.get());
  159. } finally {
  160. copyOfThreadLocals.remove();
  161. copyOfInheritableThreadLocals.remove();
  162. }
  163. }
  164. private static void restore(Field field, Object value) {
  165. try {
  166. Thread thread = Thread.currentThread();
  167. if (value == null) {
  168. field.set(thread, null);
  169. } else {
  170. tableField.set(field.get(thread), value);
  171. }
  172. } catch (IllegalAccessException e) {
  173. throw new IllegalStateException("Access denied", e);
  174. }
  175. }
  176. /* Reflection fields */
  177. private static final Field threadLocalsField;
  178. private static final Field inheritableThreadLocalsField;
  179. private static final Class<?> threadLocalMapClass;
  180. private static final Field tableField;
  181. private static final Class<?> threadLocalMapEntryClass;
  182. private static final Field threadLocalEntryValueField;
  183. static {
  184. try {
  185. threadLocalsField = field(Thread.class, "threadLocals");
  186. inheritableThreadLocalsField =
  187. field(Thread.class, "inheritableThreadLocals");
  188. threadLocalMapClass =
  189. inner(ThreadLocal.class, "ThreadLocalMap");
  190. tableField = field(threadLocalMapClass, "table");
  191. threadLocalMapEntryClass =
  192. inner(threadLocalMapClass, "Entry");
  193. threadLocalEntryValueField =
  194. field(threadLocalMapEntryClass, "value");
  195. } catch (NoSuchFieldException e) {
  196. throw new IllegalStateException(
  197. "Could not locate threadLocals field in Thread. " +
  198. "Will not be able to clear thread locals: " + e);
  199. }
  200. }
  201. }
复制代码

这是一个ThreadLocalCleaner在实践中应用的例子:

  1. import java.text.*;
  2. public class ThreadLocalCleanerExample {
  3. private static final ThreadLocal<DateFormat> df =
  4. new ThreadLocal<DateFormat>() {
  5. protected DateFormat initialValue() {
  6. return new SimpleDateFormat("yyyy-MM-dd");
  7. }
  8. };
  9. public static void main(String... args) {
  10. System.out.println("First ThreadLocalCleaner context");
  11. try (ThreadLocalCleaner tlc = new ThreadLocalCleaner(
  12. ThreadLocalChangeListener.PRINTER)) {
  13. System.out.println(System.identityHashCode(df.get()));
  14. System.out.println(System.identityHashCode(df.get()));
  15. System.out.println(System.identityHashCode(df.get()));
  16. }
  17. System.out.println("Another ThreadLocalCleaner context");
  18. try (ThreadLocalCleaner tlc = new ThreadLocalCleaner(
  19. ThreadLocalChangeListener.PRINTER)) {
  20. System.out.println(System.identityHashCode(df.get()));
  21. System.out.println(System.identityHashCode(df.get()));
  22. System.out.println(System.identityHashCode(df.get()));
  23. }
  24. }
  25. }
复制代码

你的输出结果可能会包含不同的hash code值。但是请记住我在Identity Crisis Newsletter中所说的:hash code的生成算法是一个随机数字生成器。这是我的输出。注意,在try-with-resource内部,线程局部变量的值是相同的。

  1. First ThreadLocalCleaner context
  2. 186370029
  3. 186370029
  4. 186370029
  5. Thread Thread[main,5,main] ADDED ThreadLocal class
  6. ThreadLocalCleanerExample$1 with value
  7. java.text.SimpleDateFormat@f67a0200
  8. Another ThreadLocalCleaner context
  9. 2094548358
  10. 2094548358
  11. 2094548358
  12. Thread Thread[main,5,main] ADDED ThreadLocal class
  13. ThreadLocalCleanerExample$1 with value
  14. java.text.SimpleDateFormat@f67a0200
复制代码

为了让这个代码使用起来更简单,我写了一个Facede。门面设计模式不是阻止用户使用直接使用子系统,而是提供一种更简单的接口来完成复杂的系统。最典型的方式是将最常用子系统作为方法提供,我们的门面包括两个方法:findAll(Thread) 和 printThreadLocals() 方法。findAll() 方法返回一个线程内部的Entry集合。

  1. package threadcleaner;
  2. import java.io.*;
  3. import java.lang.ref.*;
  4. import java.util.AbstractMap.*;
  5. import java.util.*;
  6. import java.util.Map.*;
  7. import java.util.function.*;
  8. import static threadcleaner.ThreadLocalCleaner.*;
  9. public class ThreadLocalCleaners {
  10. public static Collection<Entry<ThreadLocal<?>, Object>> findAll(
  11. Thread thread) {
  12. Collection<Entry<ThreadLocal<?>, Object>> result =
  13. new ArrayList<>();
  14. BiConsumer<ThreadLocal<?>, Object> adder =
  15. (key, value) ->
  16. result.add(new SimpleImmutableEntry<>(key, value));
  17. forEach(thread, adder);
  18. return result;
  19. }
  20. public static void printThreadLocals() {
  21. printThreadLocals(System.out);
  22. }
  23. public static void printThreadLocals(Thread thread) {
  24. printThreadLocals(thread, System.out);
  25. }
  26. public static void printThreadLocals(PrintStream out) {
  27. printThreadLocals(Thread.currentThread(), out);
  28. }
  29. public static void printThreadLocals(Thread thread,
  30. PrintStream out) {
  31. out.println("Thread " + thread.getName());
  32. out.println(" ThreadLocals");
  33. printTable(thread, out);
  34. }
  35. private static void printTable(
  36. Thread thread, PrintStream out) {
  37. forEach(thread, (key, value) -> {
  38. out.printf(" {%s,%s", key, value);
  39. if (value instanceof Reference) {
  40. out.print("->" + ((Reference<?>) value).get());
  41. }
  42. out.println("}");
  43. });
  44. }
  45. }
复制代码

线程可以包含两个不同类型的ThreadLocal:一个是普通的,另一个是可继承的。大部分情况下,我们使用普通的那个。可继承意味着如果你从当前线程构造出一个新的线程,则所有可继承的ThreadLocals将被新线程继承过去。非常同意。我们很少这么使用。所以现在我们可以忘了这种情况,或者永远忘记。

一个使用ThreadLocalCleaner的典型场景是和ThreadPoolExecutor一起使用。我们写一个子类,覆盖 beforeExecute() 和 afterExecute() 方法。这个类比较长,因为我们不得不编写所有的构造函数。有意思的地方在最后面。

  1. package threadcleaner;
  2. import java.util.concurrent.*;
  3. public class ThreadPoolExecutorExt extends ThreadPoolExecutor {
  4. private final ThreadLocalChangeListener listener;
  5. // Bunch of constructors following - you can ignore those
  6. public ThreadPoolExecutorExt(
  7. int corePoolSize, int maximumPoolSize, long keepAliveTime,
  8. TimeUnit unit, BlockingQueue<Runnable> workQueue) {
  9. this(corePoolSize, maximumPoolSize, keepAliveTime, unit,
  10. workQueue, ThreadLocalChangeListener.EMPTY);
  11. }
  12. public ThreadPoolExecutorExt(
  13. int corePoolSize, int maximumPoolSize, long keepAliveTime,
  14. TimeUnit unit, BlockingQueue<Runnable> workQueue,
  15. ThreadFactory threadFactory) {
  16. this(corePoolSize, maximumPoolSize, keepAliveTime, unit,
  17. workQueue, threadFactory,
  18. ThreadLocalChangeListener.EMPTY);
  19. }
  20. public ThreadPoolExecutorExt(
  21. int corePoolSize, int maximumPoolSize, long keepAliveTime,
  22. TimeUnit unit, BlockingQueue<Runnable> workQueue,
  23. RejectedExecutionHandler handler) {
  24. this(corePoolSize, maximumPoolSize, keepAliveTime, unit,
  25. workQueue, handler,
  26. ThreadLocalChangeListener.EMPTY);
  27. }
  28. public ThreadPoolExecutorExt(
  29. int corePoolSize, int maximumPoolSize, long keepAliveTime,
  30. TimeUnit unit, BlockingQueue<Runnable> workQueue,
  31. ThreadFactory threadFactory,
  32. RejectedExecutionHandler handler) {
  33. this(corePoolSize, maximumPoolSize, keepAliveTime, unit,
  34. workQueue, threadFactory, handler,
  35. ThreadLocalChangeListener.EMPTY);
  36. }
  37. public ThreadPoolExecutorExt(
  38. int corePoolSize, int maximumPoolSize, long keepAliveTime,
  39. TimeUnit unit, BlockingQueue<Runnable> workQueue,
  40. ThreadLocalChangeListener listener) {
  41. super(corePoolSize, maximumPoolSize, keepAliveTime, unit,
  42. workQueue);
  43. this.listener = listener;
  44. }
  45. public ThreadPoolExecutorExt(
  46. int corePoolSize, int maximumPoolSize, long keepAliveTime,
  47. TimeUnit unit, BlockingQueue<Runnable> workQueue,
  48. ThreadFactory threadFactory,
  49. ThreadLocalChangeListener listener) {
  50. super(corePoolSize, maximumPoolSize, keepAliveTime, unit,
  51. workQueue, threadFactory);
  52. this.listener = listener;
  53. }
  54. public ThreadPoolExecutorExt(
  55. int corePoolSize, int maximumPoolSize, long keepAliveTime,
  56. TimeUnit unit, BlockingQueue<Runnable> workQueue,
  57. RejectedExecutionHandler handler,
  58. ThreadLocalChangeListener listener) {
  59. super(corePoolSize, maximumPoolSize, keepAliveTime, unit,
  60. workQueue, handler);
  61. this.listener = listener;
  62. }
  63. public ThreadPoolExecutorExt(
  64. int corePoolSize, int maximumPoolSize, long keepAliveTime,
  65. TimeUnit unit, BlockingQueue<Runnable> workQueue,
  66. ThreadFactory threadFactory,
  67. RejectedExecutionHandler handler,
  68. ThreadLocalChangeListener listener) {
  69. super(corePoolSize, maximumPoolSize, keepAliveTime, unit,
  70. workQueue, threadFactory, handler);
  71. this.listener = listener;
  72. }
  73. /* The interest bit of this class is below ... */
  74. private static final ThreadLocal<ThreadLocalCleaner> local =
  75. new ThreadLocal<>();
  76. protected void beforeExecute(Thread t, Runnable r) {
  77. assert t == Thread.currentThread();
  78. local.set(new ThreadLocalCleaner(listener));
  79. }
  80. protected void afterExecute(Runnable r, Throwable t) {
  81. ThreadLocalCleaner cleaner = local.get();
  82. local.remove();
  83. cleaner.cleanup();
  84. }
  85. }
复制代码

你可以像使用一个普通的ThreadPoolExecutor一样使用这个类,该类不同的地方在于,当每个Runnable执行完之后需要重置线程局部变量的状态。如果需要调试系统,你也可以获取到绑定的监听器。在我们的这个例子里,你可以看到,我们将监听器绑定到我们的增加线程局部变量的LOG上。注意,在Java 8中,java.util.logging.Logger的方法使用Supplier作为参数,这意味着我们不再需要任何代码来保证日志的性能。

  1. import java.text.*;
  2. import java.util.concurrent.*;
  3. import java.util.logging.*;
  4. public class ThreadPoolExecutorExtTest {
  5. private final static Logger LOG = Logger.getLogger(
  6. ThreadPoolExecutorExtTest.class.getName()
  7. );
  8. private static final ThreadLocal<DateFormat> df =
  9. new ThreadLocal<DateFormat>() {
  10. protected DateFormat initialValue() {
  11. return new SimpleDateFormat("yyyy-MM-dd");
  12. }
  13. };
  14. public static void main(String... args)
  15. throws InterruptedException {
  16. ThreadPoolExecutor tpe = new ThreadPoolExecutorExt(
  17. 1, 1, 0, TimeUnit.SECONDS,
  18. new LinkedBlockingQueue<>(),
  19. (m, t, tl, v) -> {
  20. LOG.warning(
  21. () -> String.format(
  22. "Thread %s %s ThreadLocal %s with value %s%n",
  23. t, m, tl.getClass(), v)
  24. );
  25. }
  26. );
  27. for (int i = 0; i < 10; i++) {
  28. tpe.submit(() ->
  29. System.out.println(System.identityHashCode(df.get())));
  30. Thread.sleep(1000);
  31. }
  32. tpe.shutdown();
  33. }
  34. }
复制代码

我机器的输出结果如下:

  1. 914524658
  2. May 23, 2015 9:28:50 PM ThreadPoolExecutorExtTest lambda$main$1
  3. WARNING: Thread Thread[pool-1-thread-1,5,main]
  4. ADDED ThreadLocal class ThreadPoolExecutorExtTest$1
  5. with value java.text.SimpleDateFormat@f67a0200
  6. 957671209
  7. May 23, 2015 9:28:51 PM ThreadPoolExecutorExtTest lambda$main$1
  8. WARNING: Thread Thread[pool-1-thread-1,5,main]
  9. ADDED ThreadLocal class ThreadPoolExecutorExtTest$1
  10. with value java.text.SimpleDateFormat@f67a0200
  11. 466968587
  12. May 23, 2015 9:28:52 PM ThreadPoolExecutorExtTest lambda$main$1
  13. WARNING: Thread Thread[pool-1-thread-1,5,main]
  14. ADDED ThreadLocal class ThreadPoolExecutorExtTest$1
  15. with value java.text.SimpleDateFormat@f67a0200
复制代码

现在,这段代码还没有在生产服务器上经过严格的考验,所以请谨慎使用。非常感谢你的阅读和支持。我真的非常感激。

Kind regards

Heinz

原文链接: javaspecialists 翻译: ImportNew.com - paddx
译文链接: http://www.importnew.com/16112.html


最新评论

小黑屋|在路上 ( 蜀ICP备15035742号-1 

;

GMT+8, 2025-7-10 10:05

Copyright 2015-2025 djqfx

返回顶部