Skip to content

Commit 41ec178

Browse files
Concurrency fix + simplification
1 parent a440983 commit 41ec178

1 file changed

Lines changed: 4 additions & 12 deletions

File tree

google-cloud-logging/src/main/java/com/google/cloud/logging/LoggingHandler.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public class LoggingHandler extends Handler {
9696
private final LoggingOptions options;
9797
private final WriteOption[] writeOptions;
9898
private List<LogEntry> buffer = new LinkedList<>();
99-
private Logging logging;
99+
private volatile Logging logging;
100100
private Level flushLevel;
101101
private long flushSize;
102102

@@ -390,23 +390,15 @@ private void flush(List<LogEntry> flushBuffer, WriteOption[] flushWriteOptions)
390390
* Closes the handler and the associated {@link Logging} object.
391391
*/
392392
@Override
393-
public void close() throws SecurityException {
394-
Logging loggingToClose = null;
393+
public synchronized void close() throws SecurityException {
395394
if (logging != null) {
396-
synchronized (this) {
397-
if (logging != null) {
398-
loggingToClose = logging;
399-
logging = null;
400-
}
401-
}
402-
}
403-
if (loggingToClose != null) {
404395
try {
405-
loggingToClose.close();
396+
logging.close();
406397
} catch (Exception ex) {
407398
// ignore
408399
}
409400
}
401+
logging = null;
410402
}
411403

412404
/**

0 commit comments

Comments
 (0)