-
Notifications
You must be signed in to change notification settings - Fork 45
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
Implement PausableScheduledThreadPool #61
Conversation
Codecov Report
@@ Coverage Diff @@
## master #61 +/- ##
============================================
- Coverage 84.69% 84.69% -0.01%
- Complexity 746 756 +10
============================================
Files 58 59 +1
Lines 2150 2182 +32
Branches 320 321 +1
============================================
+ Hits 1821 1848 +27
- Misses 187 190 +3
- Partials 142 144 +2
Continue to review full report at Codecov.
|
src/main/java/com/baidu/hugegraph/threadpool/PausableScheduledThreadPool.java
Outdated
Show resolved
Hide resolved
src/main/java/com/baidu/hugegraph/threadpool/PausableScheduledThreadPool.java
Outdated
Show resolved
Hide resolved
src/main/java/com/baidu/hugegraph/threadpool/PausableScheduledThreadPool.java
Outdated
Show resolved
Hide resolved
this.paused = false; | ||
this.notifyAll(); | ||
synchronized (this) { |
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.
move this.paused = false;
into synchronized block to avoid race between resumeSchedule and resumeSchedule
protected synchronized void beforeExecute(Thread t, Runnable r) { | ||
if (this.paused) { | ||
protected void beforeExecute(Thread t, Runnable r) { | ||
synchronized (this) { |
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.
keep all paused writing synchronized
618678a
System.out.println("counter: " + counter.incrementAndGet()); | ||
}, 2, 2, TimeUnit.SECONDS); | ||
|
||
Thread.sleep(4500); |
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.
4500L
AtomicInteger counter = new AtomicInteger(0); | ||
executor.scheduleWithFixedDelay(() -> { | ||
System.out.println("counter: " + counter.incrementAndGet()); | ||
}, 2, 2, TimeUnit.SECONDS); |
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.
2, 2 -> 2L, 2L
|
||
// pause | ||
executor.pauseSchedule(); | ||
Thread.sleep(2000); |
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.
2000L
|
||
// resume | ||
executor.resumeSchedule(); | ||
Thread.sleep(2000); |
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.
2000L
AtomicInteger counter = new AtomicInteger(0); | ||
executor.scheduleAtFixedRate(() -> { | ||
System.out.println("counter: " + counter.incrementAndGet()); | ||
}, 2, 2, TimeUnit.SECONDS); |
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.
ditto
executor.scheduleAtFixedRate(() -> { | ||
System.out.println("counter: " + counter.incrementAndGet()); | ||
}, 2, 2, TimeUnit.SECONDS); | ||
Thread.sleep(4500); |
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.
ditto
|
||
// pause | ||
executor.pauseSchedule(); | ||
Thread.sleep(2000); |
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.
ditto
|
||
// resume | ||
executor.resumeSchedule(); | ||
Thread.sleep(2000); |
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.
ditto
executor.pauseSchedule(); | ||
|
||
executor.shutdownNow(); | ||
executor.awaitTermination(3, TimeUnit.SECONDS); |
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.
ditto
src/main/java/com/baidu/hugegraph/threadpool/PausableScheduledThreadPool.java
Outdated
Show resolved
Hide resolved
src/test/java/com/baidu/hugegraph/unit/threadpool/PausableScheduledThreadPoolTest.java
Outdated
Show resolved
Hide resolved
55864c3
to
978b157
Compare
LicenseVerifyParamTest.class, | ||
MachineInfoTest.class, | ||
LicenseManagerTest.class, | ||
// LockManagerTest.class, |
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.
keep origin
No description provided.