-
Notifications
You must be signed in to change notification settings - Fork 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
fix issues/1463 : Make default JUL-based logging asynchronous #3136
Conversation
Hi, could you please sign the CLA here: https://cla-assistant.io/alibaba/Sentinel?pullRequest=3136 |
add asynchronous test cases |
@@ -42,6 +47,9 @@ class ConsoleHandler extends Handler { | |||
* A Handler which publishes log records to System.err. | |||
*/ | |||
private StreamHandler stderrHandler; | |||
@SuppressWarnings("PMD.ThreadPoolCreationRule") |
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.
You have to follow the Java code guidelines rather than skip it with @SuppressWarnings
. The queue should be bounded.
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.
has deleted
@@ -34,6 +39,10 @@ public SimpleDateFormat initialValue() { | |||
} | |||
}; | |||
|
|||
@SuppressWarnings("PMD.ThreadPoolCreationRule") |
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.
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.
has deleted
@@ -42,6 +47,9 @@ class ConsoleHandler extends Handler { | |||
* A Handler which publishes log records to System.err. | |||
*/ | |||
private StreamHandler stderrHandler; | |||
@SuppressWarnings("PMD.ThreadPoolCreationRule") | |||
private final ExecutorService executor = Executors.newSingleThreadExecutor( | |||
new NamedThreadFactory("sentinel-log-executor", 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.
You may need to refine the thread name so that we could distinguish the actual type of the logging (e.g. to file or to console).
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.
has renamed
@@ -79,6 +89,12 @@ public void flush() { | |||
|
|||
@Override | |||
public void close() throws SecurityException { | |||
executor.shutdown(); | |||
try { | |||
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.
Should we block and wait for termination here?
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.
has deleted
sentinel-core/src/main/java/com/alibaba/csp/sentinel/log/jul/ConsoleHandler.java
Outdated
Show resolved
Hide resolved
sentinel-core/src/main/java/com/alibaba/csp/sentinel/log/jul/DateFileLogHandler.java
Outdated
Show resolved
Hide resolved
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 test cases could be improved later.
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.
LGTM
Thanks for contributing! |
* fix issues/1463 : Make default JUL-based logging asynchronous
Describe what this PR does / why we need it
Make default JUL-based logging asynchronous
Does this pull request fix one issue?
Fixes #1463
Describe how you did it
use java.util.concurrent.Executor, submit the log task into single thread.
Describe how to verify it
Special notes for reviews