Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Tracked by #5362
halibobo1205 opened this issue Aug 15, 2023 · 2 comments · Fixed by #5425
Closed
Tracked by #5362

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

halibobo1205 opened this issue Aug 15, 2023 · 2 comments · Fixed by #5425
Assignees

Comments

@halibobo1205
Copy link
Contributor

halibobo1205 commented Aug 15, 2023

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.

@halibobo1205 halibobo1205 changed the title Organize all ThreadExecutors with explicit name and time-wait closure Organize all ThreadExecutors with explicit name and time-wait shutdown Aug 15, 2023
@halibobo1205 halibobo1205 self-assigned this Aug 15, 2023
@halibobo1205 halibobo1205 added this to the GreatVoyage-v4.7.3 milestone Aug 15, 2023
@ClarkChenc
Copy link

I wonder why we need time-wait shutdown?

@halibobo1205
Copy link
Contributor Author

I wonder why we need time-wait shutdown?

@ClarkChenc Try to ensure that the thread being executed completes properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants