-
-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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
Refactor Busy-Waiting Loops to Improve Efficiency #3123
base: master
Are you sure you want to change the base?
Changes from all commits
86efd3c
8aa0647
d5864d9
0d0bb7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,9 +32,7 @@ | |
*/ | ||
@Slf4j | ||
public class ServiceExecutor implements Runnable { | ||
|
||
private final MessageQueue msgQueue; | ||
|
||
public ServiceExecutor(MessageQueue msgQueue) { | ||
this.msgQueue = msgQueue; | ||
} | ||
|
@@ -51,9 +49,10 @@ public void run() { | |
LOGGER.info(msg + " is served."); | ||
} else { | ||
LOGGER.info("Service Executor: Waiting for Messages to serve .. "); | ||
synchronized (msgQueue.serviceExecutorWait) { | ||
msgQueue.serviceExecutorWait.wait(); | ||
} | ||
Comment on lines
+52
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In
Comment on lines
+52
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
} | ||
|
||
Thread.sleep(1000); | ||
} | ||
} catch (Exception e) { | ||
LOGGER.error(e.getMessage()); | ||
|
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.
In
MessageQueue
, ensure thatserviceExecutorWait
is properly synchronized to prevent race conditions when multiple threads access it concurrently.