Skip to content

Organize all ThreadExecutors with explicit name and time-wait shutdown #5422

Description

@halibobo1205

Rationale

Why should this feature exist?

  1. At present, the java-tron thread pool name is not clearly defined, a thread is created with the following (default) name: Thread[pool-1-thread-1], which isn’t helpful and doesn’t let you differentiate threads by name. As you can see, this isn't useful.
  2. Some thread pools don't have a graceful shutdown.

What are the use-cases?

In case of performance issues: thread dumps and using the top command. In both cases, it’s useful to know what function does a thread service, as the stacktrace in the dump might not always be revealing.

A tool for quick investigation is top. More precisely, top -H -p . This shows the usual top table, but the -H flag means that threads for the chosen process should be printed. You basically get the most CPU-heavy and currently active threads, by name. In those cases, it’s extremely useful to have custom names.

  1. DynamicArgs.java#L29
  2. Manager.java#L536
  3. TransactionsMsgHandler.java#L55

Implementation

All of these executors have a thread factory. It’s hidden in the default factory method, but you can supply a thread factory. If not supplied, a default thread factory is used whenever a thread is needed.

  1. Name threads and thread-pools of ExecutorService.
ThreadFactory factory = new ThreadFactoryBuilder().setNameFormat("my-sad-thread-%d").build();
 ExecutorService es = Executors.newFixedThreadPool(4, factory);
  1. Make time-wait shutdown(awaitTermination) for thread-pools of ExecutorService.
 es.shutdown();
 es.awaitTermination(60, java.util.concurrent.TimeUnit.SECONDS);

Are you willing to implement this feature?
Yes.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions