perf: Code optimization points (#9552)

* perf: Replace the dead loop with while

* perf: Jump statements should not be redundant

* Update CredentialWatcher.java

Co-authored-by: elsez <67528597+zhantiao@users.noreply.github.com>
This commit is contained in:
elsez 2022-11-22 15:29:07 +08:00 committed by GitHub
parent 93c6fe0167
commit e23ec89892
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -102,18 +102,12 @@ public class DefaultPublisher extends Thread implements EventPublisher {
int waitTimes = 60;
// To ensure that messages are not lost, enable EventHandler when
// waiting for the first Subscriber to register
for (; ; ) {
if (shutdown || hasSubscriber() || waitTimes <= 0) {
break;
}
while (!shutdown && !hasSubscriber() && waitTimes > 0) {
ThreadUtils.sleep(1000L);
waitTimes--;
}
for (; ; ) {
if (shutdown) {
break;
}
while (!shutdown) {
final Event event = queue.take();
receiveEvent(event);
UPDATER.compareAndSet(this, lastEventSequence, Math.max(lastEventSequence, event.sequence()));