Skip to content

Commit

Permalink
Merge pull request #25221 from kaido207/Fix_LoggingPump
Browse files Browse the repository at this point in the history
Fix #25220 The number of Logging pump threads grows infinitely
  • Loading branch information
dmatej authored Nov 21, 2024
2 parents 1eb9920 + d5758ff commit 6177d58
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,21 @@ private void drainLogRecords() {

private void initStandardStreamsLogging() {
trace(GlassFishLogHandler.class, "initStandardStreamsLogging()");

LoggingPrintStream prevStdoutStream = this.stdoutStream;
LoggingPrintStream prevStderrStream = this.stderrStream;

this.stdoutStream = LoggingPrintStream.create(STDOUT_LOGGER, INFO, 5000, configuration.getEncoding());
this.stderrStream = LoggingPrintStream.create(STDERR_LOGGER, SEVERE, 1000, configuration.getEncoding());
System.setOut(this.stdoutStream);
System.setErr(this.stderrStream);

if (prevStdoutStream != null) {
prevStdoutStream.close();
}
if (prevStderrStream != null) {
prevStderrStream.close();
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ private static final class Pump extends Thread {

private final LogRecordBuffer buffer;
private final Logger logger;
private volatile boolean pumpClosed;

private Pump(final Logger logger, final LogRecordBuffer buffer) {
this.buffer = buffer;
Expand All @@ -151,7 +152,7 @@ private Pump(final Logger logger, final LogRecordBuffer buffer) {
@Override
public void run() {
// the thread will be interrupted by it's owner finally
while (true) {
while (!pumpClosed) {
try {
logAllPendingRecordsOrWait();
} catch (final Exception e) {
Expand All @@ -169,6 +170,7 @@ public void run() {
* The pump can be locked, waiting
*/
void shutdown() {
pumpClosed = true;
this.interrupt();
// we interrupted waiting or working thread, now we have to process remaining records.
logAllPendingRecords();
Expand Down

0 comments on commit 6177d58

Please sign in to comment.