thread-factory

A set of utilities for creating custom ThreadFactory objects

Лицензия

Лицензия

Группа

Группа

com.pivovarit
Идентификатор

Идентификатор

thread-factory
Последняя версия

Последняя версия

0.0.1
Дата

Дата

Тип

Тип

jar
Описание

Описание

thread-factory
A set of utilities for creating custom ThreadFactory objects
Система контроля версий

Система контроля версий

https://github.com/pivovarit/thread-factory

Скачать thread-factory

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.pivovarit/thread-factory/ -->
<dependency>
    <groupId>com.pivovarit</groupId>
    <artifactId>thread-factory</artifactId>
    <version>0.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.pivovarit/thread-factory/
implementation 'com.pivovarit:thread-factory:0.0.1'
// https://jarcasting.com/artifacts/com.pivovarit/thread-factory/
implementation ("com.pivovarit:thread-factory:0.0.1")
'com.pivovarit:thread-factory:jar:0.0.1'
<dependency org="com.pivovarit" name="thread-factory" rev="0.0.1">
  <artifact name="thread-factory" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.pivovarit', module='thread-factory', version='0.0.1')
)
libraryDependencies += "com.pivovarit" % "thread-factory" % "0.0.1"
[com.pivovarit/thread-factory "0.0.1"]

Зависимости

test (3)

Идентификатор библиотеки Тип Версия
org.slf4j : slf4j-simple jar 1.7.5
org.junit.jupiter : junit-jupiter-engine jar 5.3.2
org.assertj : assertj-core jar 3.8.0

Модули Проекта

Данный проект не имеет модулей.

thread-factory

Build Status License Maven Central

Rationale

Custom thread pool naming is critical for debuggability.

Unfortunately, relying on default naming schemes often leads to situations where most of our threads are named in a cryptic manner:

Alt text

Using core Java, there's no easy way to create custom ThreadFactory instances.

Basic API

  • ThreadFactories.prefixed(String prefix)

  • ThreadFactories.prefixed(String prefix, ThreadFactory base)

  • ThreadFactories.suffixed(String suffix)

  • ThreadFactories.suffixed(String suffix, ThreadFactory base)

  • ThreadFactories.builder(String nameFormat)

    • withDaemonThreads(boolean daemon)
    • withUncaughtExceptionHandler(UncaughtExceptionHandler handler)
    • fromThreadFactory(ThreadFactory backingThreadFactory)
    • build()

Maven Dependencies

<dependency>
    <groupId>com.pivovarit</groupId>
    <artifactId>thread-factory</artifactId>
    <version>0.0.1</version>
</dependency>
Gradle
compile 'com.pivovarit:thread-factory:0.0.1'

Examples

Tips

Dependencies

None - the library is implemented using core Java libraries.

Version history

0.0.1 (23-01-2019)

  • Initial project version

What if I don't want to add a new library just for the sake of prefixing threads?

That's reasonable. Just copy over the following code and use at will:

import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

/**
 * @author Grzegorz Piwowarek
 */
public class CustomThreadFactory implements ThreadFactory {

    private String prefix;
    private ThreadFactory defaultThreadFactory = Executors.defaultThreadFactory();

    CustomThreadFactory(String prefix) {
        this.prefix = prefix;
    }

    @Override
    public Thread newThread(Runnable task) {
        Thread thread = defaultThreadFactory.newThread(task);
        thread.setName(prefix + "-" + thread.getName());
        return thread;
    }
}

Версии библиотеки

Версия
0.0.1