View Javadoc

1   package com.atlassian.event.internal;
2   
3   import java.util.concurrent.Executors;
4   import java.util.concurrent.ThreadFactory;
5   
6   import static com.google.common.base.Preconditions.checkNotNull;
7   
8   /**
9    * <p>A thread factory that will name the threads <strong>AtlassianEvent::[thread_name]</strong>.</p>
10   * <p>If you need your own {@link java.util.concurrent.ThreadFactory} we recommend delegating the Thread creation to
11   * this implementation.</p>
12   */
13  public final class EventThreadFactory implements ThreadFactory {
14      private final ThreadFactory delegateThreadFactory;
15  
16      public EventThreadFactory() {
17          this(Executors.defaultThreadFactory());
18      }
19  
20      public EventThreadFactory(ThreadFactory delegateThreadFactory) {
21          this.delegateThreadFactory = checkNotNull(delegateThreadFactory);
22      }
23  
24      public Thread newThread(Runnable r) {
25          final Thread thread = delegateThreadFactory.newThread(r);
26          thread.setName("AtlassianEvent::" + thread.getName());
27          return thread;
28      }
29  }