这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@joerg1985
Copy link
Contributor

Description

The intention of this PR was to have less idling threads created by the Timer instances.
A ScheduledExecutorService is now used instead to have only some worker threads.

This PR will also fix two issues of this class:

  1. The commitTimerTask field was never set to another value than null.
    See line 411 in the old version, it should be this.commitTimerTask = new CommitTimerTask(); and not commitTimerTask = new CommitTimerTask();
  2. The conversion between milliseconds and nanoseconds was incorrect it should have been maxDeferredPeriod * 1000000L and not maxDeferredPeriod * 1000L.

…stance

Signed-off-by: Jörg Sautter <joerg.sautter@gmx.net>
Signed-off-by: Jörg Sautter <joerg.sautter@gmx.net>
@joerg1985 joerg1985 requested a review from a team as a code owner November 15, 2023 19:28
@kaikreuzer
Copy link
Member

kaikreuzer commented Nov 22, 2023

Thanks for this PR!
Just for my understanding: Why are there idling threads? I would have thought that the current implementation is meant to have only exactly one thread being active, doing the next scheduled flush. Through the bug that you have discovered, the cancelling and rescheduling does not work, so I assume that this is the reason for the multiple threads, isn't it?

But if this is the case, fixing the bug should be enough. Introducing a thread pool (with 10 threads) does not seem to be very useful here or am I missing something?

@joerg1985
Copy link
Contributor Author

There was one instance per file and one timer thread per instance, on my system 20 instances are a live, backed by 20 threads. Now there is a named pool of 5 threads (as per default configuration) shared by all 20 instances.

ThreadPoolManager.getScheduledPool will allways return the same instance from the internal cache. I did not make the scheduledExecutorService field static, as other areas using the ThreadPoolManager store the pool in an not static field. So i did assume this is the code style used here.

Copy link
Member

@kaikreuzer kaikreuzer left a comment

Choose a reason for hiding this comment

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

Ah, that's what I was missing indeed - we have of course many instances of JsonStorage. Thanks for the explanation!
Yeah, in this case your change makes a lot of sense. Thanks for it and the fixes that come included!

@kaikreuzer kaikreuzer added the bug An unexpected problem or unintended behavior of the Core label Nov 22, 2023
@kaikreuzer kaikreuzer merged commit bdb1e55 into openhab:main Nov 22, 2023
@kaikreuzer kaikreuzer added this to the 4.1 milestone Nov 22, 2023
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/looking-for-brave-testers-less-threads-for-rule-engine/157224/3

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

Labels

bug An unexpected problem or unintended behavior of the Core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants