feat(all):name thread pools by halibobo1205 · Pull Request #5425 · tronprotocol/java-tron

@halibobo1205

lurais

Executors.newSingleThreadScheduledExecutor(
new ThreadFactoryBuilder().setNameFormat("db-stats-thread-%d").build());

private final String esName = "db-stats";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be static?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For singleton, there should be no need.

lurais

public static class BatchValidateSign extends PrecompiledContract {

private static final ExecutorService workers;
private static final String workersName = "validate-sign-contract";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this managed by ExecutorServiceManager?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, do you have any good ideas?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we can just move the excutors name and the construction into ExecutorServiceManager, then the lifecycle and all the executors is controlled in ExecutorServiceManager , a certain executor shall be obtained by using a name(may be obtained by spring injection).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thread pool shutdown is better controlled by the service, not the manager but this one is a special case, so maybe it can be done this way.

xxo1shine

smartContractExecutor.scheduleWithFixedDelay(() -> {
try {
while (queue.size() < MAX_SMART_CONTRACT_SUBMIT_SIZE) {
while (queue.size() < MAX_SMART_CONTRACT_SUBMIT_SIZE && smartContractQueue.size() > 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add this logic, if the queue has no elements, it will enter an infinite loop.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TrxEvent event = smartContractQueue.take();
Retrieves and removes the head of this queue, waiting if necessary until an element becomes available.

smartContractExecutor.scheduleWithFixedDelay(() -> {
try {
while (queue.size() < MAX_SMART_CONTRACT_SUBMIT_SIZE) {
while (queue.size() < MAX_SMART_CONTRACT_SUBMIT_SIZE && smartContractQueue.size() > 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try not to change the original logic, if it is a bug, it is recommended to submit a pr separately.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wubin01 , As explained above, smartContractExecutor.shutdown() -> ExecutorServiceManager.shutdownAndAwaitTermination(smartContractExecutor, smartEsName)
if queue is empty, will block 60s

jwrct

@@ -117,18 +116,6 @@ public void init() {
exitThread.start();
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not adjust exitThread to SingleThreadExecutor?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exitThread will only run once, when it receives the exit signal LockSupport.unpark(exitThread) then System.exit(1), otherwise it blocks in here LockSupport.park(), unlike other single-thread that has while(true) logic.

jwrct

xxo1shine

317787106