mirror of
https://github.com/apache/rocketmq.git
synced 2026-09-19 02:23:24 +08:00
[ISSUE #6488] Use ServiceThread#shutdown to replace the deprecated ServiceThread#stop method (#6489)
This commit is contained in:
@@ -71,7 +71,7 @@ public class AckMessageProcessor implements NettyRequestProcessor {
|
||||
|
||||
public void shutdownPopReviveService() {
|
||||
for (PopReviveService popReviveService : popReviveServices) {
|
||||
popReviveService.stop();
|
||||
popReviveService.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -67,9 +67,8 @@ public abstract class ServiceThread implements Runnable {
|
||||
this.stopped = true;
|
||||
log.info("shutdown thread[{}] interrupt={} ", getServiceName(), interrupt);
|
||||
|
||||
if (hasNotified.compareAndSet(false, true)) {
|
||||
waitPoint.countDown(); // notify
|
||||
}
|
||||
//if thead is waiting, wakeup it
|
||||
wakeup();
|
||||
|
||||
try {
|
||||
if (interrupt) {
|
||||
@@ -91,28 +90,6 @@ public abstract class ServiceThread implements Runnable {
|
||||
return JOIN_TIME;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void stop() {
|
||||
this.stop(false);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void stop(final boolean interrupt) {
|
||||
if (!started.get()) {
|
||||
return;
|
||||
}
|
||||
this.stopped = true;
|
||||
log.info("stop thread[{}],interrupt={} ", this.getServiceName(), interrupt);
|
||||
|
||||
if (hasNotified.compareAndSet(false, true)) {
|
||||
waitPoint.countDown(); // notify
|
||||
}
|
||||
|
||||
if (interrupt) {
|
||||
this.thread.interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
public void makeStop() {
|
||||
if (!started.get()) {
|
||||
return;
|
||||
|
||||
@@ -31,12 +31,6 @@ public class ServiceThreadTest {
|
||||
shutdown(true, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStop() {
|
||||
stop(true);
|
||||
stop(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMakeStop() {
|
||||
ServiceThread testServiceThread = startTestServiceThread();
|
||||
@@ -116,23 +110,4 @@ public class ServiceThreadTest {
|
||||
assertEquals(true, testServiceThread.hasNotified.get());
|
||||
assertEquals(0, testServiceThread.waitPoint.getCount());
|
||||
}
|
||||
|
||||
public void stop(boolean interrupt) {
|
||||
ServiceThread testServiceThread = startTestServiceThread();
|
||||
stop0(interrupt, testServiceThread);
|
||||
// repeat
|
||||
stop0(interrupt, testServiceThread);
|
||||
}
|
||||
|
||||
private void stop0(boolean interrupt, ServiceThread testServiceThread) {
|
||||
if (interrupt) {
|
||||
testServiceThread.stop(true);
|
||||
} else {
|
||||
testServiceThread.stop();
|
||||
}
|
||||
assertEquals(true, testServiceThread.isStopped());
|
||||
assertEquals(true, testServiceThread.hasNotified.get());
|
||||
assertEquals(0, testServiceThread.waitPoint.getCount());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user