-
Notifications
You must be signed in to change notification settings - Fork 11.6k
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
[Optimization] Replace Timer to ScheduleExecutorService #4208
[Optimization] Replace Timer to ScheduleExecutorService #4208
Conversation
Two small suggestions. |
@@ -317,7 +320,8 @@ class StatsBenchmarkBatchProducer { | |||
|
|||
private final LongAdder sendMessageFailedCount = new LongAdder(); | |||
|
|||
private final Timer timer = new Timer("BenchmarkTimerThread", true); | |||
private final ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1, | |||
new BasicThreadFactory.Builder().namingPattern("BenchmarkTimerThread-%d").daemon(true).build()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's better to use ThreadFactoryImpl
, just like this:
private final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryImpl( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Emmm, I prefer to like present way
@@ -360,17 +364,17 @@ public LongAdder getSendMessageFailedCount() { | |||
|
|||
public void start() { | |||
|
|||
timer.scheduleAtFixedRate(new TimerTask() { | |||
executorService.scheduleAtFixedRate(new TimerTask() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code can be more concise, such as using a lambda expression
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea
The client module will be compile with jdk 1.7 or jdk 1.6, which not support lambda |
@@ -360,17 +364,17 @@ public LongAdder getSendMessageFailedCount() { | |||
|
|||
public void start() { | |||
|
|||
timer.scheduleAtFixedRate(new TimerTask() { | |||
executorService.scheduleAtFixedRate(new TimerTask() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems better to implement Runnable anonymously
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
@@ -317,7 +320,8 @@ class StatsBenchmarkBatchProducer { | |||
|
|||
private final LongAdder sendMessageFailedCount = new LongAdder(); | |||
|
|||
private final Timer timer = new Timer("BenchmarkTimerThread", true); | |||
private final ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1, | |||
new BasicThreadFactory.Builder().namingPattern("BenchmarkTimerThread-%d").daemon(true).build()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A unified style is recommended
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get your meaning,Can you provide more detail info
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as @cserwen mentioned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok,Thanks for your suggestions
48508df
to
93b2be1
Compare
I have modified it,Please check if have other issue |
@@ -317,7 +318,8 @@ class StatsBenchmarkBatchProducer { | |||
|
|||
private final LongAdder sendMessageFailedCount = new LongAdder(); | |||
|
|||
private final Timer timer = new Timer("BenchmarkTimerThread", true); | |||
private final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryImpl( | |||
"BenchmarkTimerThread")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
daemon thread
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your checking,I have solved it
Codecov Report
@@ Coverage Diff @@
## develop #4208 +/- ##
=============================================
- Coverage 48.13% 48.09% -0.04%
+ Complexity 5038 5030 -8
=============================================
Files 636 636
Lines 42506 42506
Branches 5568 5568
=============================================
- Hits 20459 20443 -16
- Misses 19564 19575 +11
- Partials 2483 2488 +5
Continue to review full report at Codecov.
|
1 similar comment
@@ -317,7 +318,8 @@ class StatsBenchmarkBatchProducer { | |||
|
|||
private final LongAdder sendMessageFailedCount = new LongAdder(); | |||
|
|||
private final Timer timer = new Timer("BenchmarkTimerThread", true); | |||
private final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryImpl( | |||
"BenchmarkTimerThread", Boolean.TRUE)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indent here maybe wrong, pls import rmq_codeStyle.xml in style folder and reformat the code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK, if indent is wrong,the checking will not passing
* replace Timer to ScheduleExecutorService * replace timetask to runnable * Change the style of creating ThreadPoolExecutor * Remove unused import * set daemon * checkstyle
Make sure set the target branch to
develop
What is the purpose of the change
Replace Timer to ScheduleExecutorService
Follow this checklist to help us incorporate your contribution quickly and easily. Notice,
it would be helpful if you could finish the following 5 checklist(the last one is not necessary)before request the community to review your PR
.[ISSUE #123] Fix UnknownException when host config not exist
. Each commit in the pull request should have a meaningful subject line and body.mvn -B clean apache-rat:check findbugs:findbugs checkstyle:checkstyle
to make sure basic checks pass. Runmvn clean install -DskipITs
to make sure unit-test pass. Runmvn clean test-compile failsafe:integration-test
to make sure integration-test pass.