set names for threads

This commit is contained in:
Sebastian Sdorra
2012-12-09 20:45:16 +01:00
parent 5178dca30d
commit ced9abb77f
3 changed files with 53 additions and 11 deletions

View File

@@ -26,16 +26,28 @@
* http://bitbucket.org/sdorra/scm-manager * http://bitbucket.org/sdorra/scm-manager
* *
*/ */
package sonia.scm.event; package sonia.scm.event;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.eventbus.AsyncEventBus; import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus; import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.ThrowingEventBus; import com.google.common.eventbus.ThrowingEventBus;
import java.util.concurrent.Executors; import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.apache.shiro.concurrent.SubjectAwareExecutorService; import org.apache.shiro.concurrent.SubjectAwareExecutorService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
//~--- JDK imports ------------------------------------------------------------
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
/** /**
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
@@ -43,12 +55,16 @@ import org.slf4j.LoggerFactory;
public class GuavaScmEventBus extends ScmEventBus public class GuavaScmEventBus extends ScmEventBus
{ {
/** Field description */
private static final String THREAD_NAME = "EventBus-%s";
/** /**
* the logger for GuavaScmEventBus * the logger for GuavaScmEventBus
*/ */
private static final Logger logger = LoggerFactory.getLogger( private static final Logger logger =
GuavaScmEventBus.class); LoggerFactory.getLogger(GuavaScmEventBus.class);
//~--- constructors ---------------------------------------------------------
/** /**
* Constructs a new ScmEventBus * Constructs a new ScmEventBus
@@ -57,10 +73,17 @@ public class GuavaScmEventBus extends ScmEventBus
public GuavaScmEventBus() public GuavaScmEventBus()
{ {
eventBus = new ThrowingEventBus(); eventBus = new ThrowingEventBus();
//J-
ThreadFactory factory = new ThreadFactoryBuilder()
.setNameFormat(THREAD_NAME).build();
asyncEventBus = new AsyncEventBus( asyncEventBus = new AsyncEventBus(
new SubjectAwareExecutorService(Executors.newCachedThreadPool())); new SubjectAwareExecutorService(Executors.newCachedThreadPool(factory))
);
//J+
} }
//~--- methods --------------------------------------------------------------
/** /**
* {@inheritDoc} * {@inheritDoc}

View File

@@ -37,6 +37,7 @@ package sonia.scm.repository;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider; import com.google.inject.Provider;
import com.google.inject.Singleton; import com.google.inject.Singleton;
@@ -76,6 +77,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@@ -93,6 +95,8 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager
//~--- constructors --------------------------------------------------------- //~--- constructors ---------------------------------------------------------
private static final String THREAD_NAME = "Hook-%s";
/** /**
* Constructs ... * Constructs ...
* *
@@ -118,8 +122,14 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager
this.repositoryListenersProvider = repositoryListenersProvider; this.repositoryListenersProvider = repositoryListenersProvider;
this.repositoryHooksProvider = repositoryHooksProvider; this.repositoryHooksProvider = repositoryHooksProvider;
this.executorService = //J-
new SubjectAwareExecutorService(Executors.newCachedThreadPool()); ThreadFactory factory = new ThreadFactoryBuilder()
.setNameFormat(THREAD_NAME).build();
this.executorService = new SubjectAwareExecutorService(
Executors.newCachedThreadPool(factory)
);
//J+
handlerMap = new HashMap<String, RepositoryHandler>(); handlerMap = new HashMap<String, RepositoryHandler>();
types = new HashSet<Type>(); types = new HashSet<Type>();

View File

@@ -38,6 +38,7 @@ package sonia.scm.template;
import com.github.mustachejava.Mustache; import com.github.mustachejava.Mustache;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.google.common.util.concurrent.UncheckedExecutionException; import com.google.common.util.concurrent.UncheckedExecutionException;
import com.google.inject.Inject; import com.google.inject.Inject;
@@ -50,6 +51,7 @@ import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
@@ -65,6 +67,9 @@ public class MustacheTemplateEngine implements TemplateEngine
public static final TemplateType TYPE = new TemplateType("mustache", public static final TemplateType TYPE = new TemplateType("mustache",
"Mustache", "mustache"); "Mustache", "mustache");
/** Field description */
private static final String THREAD_NAME = "Mustache-%s";
/** /**
* the logger for MustacheTemplateEngine * the logger for MustacheTemplateEngine
*/ */
@@ -83,7 +88,11 @@ public class MustacheTemplateEngine implements TemplateEngine
public MustacheTemplateEngine(ServletContext context) public MustacheTemplateEngine(ServletContext context)
{ {
factory = new ServletMustacheFactory(context); factory = new ServletMustacheFactory(context);
factory.setExecutorService(Executors.newCachedThreadPool());
ThreadFactory threadFactory =
new ThreadFactoryBuilder().setNameFormat(THREAD_NAME).build();
factory.setExecutorService(Executors.newCachedThreadPool(threadFactory));
} }
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------