Skip to content

Conversation

@halibobo1205
Copy link
Contributor

close #5422 .

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

private final String esName = "db-stats";
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be static?

Copy link
Contributor Author

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.

@halibobo1205 halibobo1205 self-assigned this Aug 17, 2023
public static class BatchValidateSign extends PrecompiledContract {

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

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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).

Copy link
Contributor Author

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.

@halibobo1205 halibobo1205 added this to the GreatVoyage-v4.7.3 milestone Aug 18, 2023
smartContractExecutor.scheduleWithFixedDelay(() -> {
try {
while (queue.size() < MAX_SMART_CONTRACT_SUBMIT_SIZE) {
while (queue.size() < MAX_SMART_CONTRACT_SUBMIT_SIZE && smartContractQueue.size() > 0) {
Copy link
Contributor

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.

Copy link
Contributor Author

@halibobo1205 halibobo1205 Aug 21, 2023

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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

});
exitThread.setName("exit-thread");
exitThread.start();
}
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@halibobo1205 halibobo1205 merged commit 03e903e into tronprotocol:develop Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:enhancement minor enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Organize all ThreadExecutors with explicit name and time-wait shutdown

5 participants