1
1
/**
2
2
* Logback: the reliable, generic, fast and flexible logging framework.
3
- * Copyright (C) 1999-2015 , QOS.ch. All rights reserved.
3
+ * Copyright (C) 1999-2024 , QOS.ch. All rights reserved.
4
4
*
5
5
* This program and the accompanying materials are dual-licensed under
6
6
* either the terms of the Eclipse Public License v1.0 as published by
15
15
16
16
import java .util .ArrayList ;
17
17
import java .util .List ;
18
+ import java .util .concurrent .atomic .AtomicInteger ;
19
+ import java .util .concurrent .atomic .LongAdder ;
18
20
19
21
import ch .qos .logback .core .helpers .CyclicBuffer ;
20
22
import ch .qos .logback .core .spi .LogbackLock ;
@@ -28,14 +30,14 @@ public class BasicStatusManager implements StatusManager {
28
30
public static final int MAX_HEADER_COUNT = 150 ;
29
31
public static final int TAIL_SIZE = 150 ;
30
32
31
- int count = 0 ;
33
+ final LongAdder count = new LongAdder () ;
32
34
33
35
// protected access was requested in http://jira.qos.ch/browse/LBCORE-36
34
36
final protected List <Status > statusList = new ArrayList <Status >();
35
37
final protected CyclicBuffer <Status > tailBuffer = new CyclicBuffer <Status >(TAIL_SIZE );
36
38
final protected LogbackLock statusListLock = new LogbackLock ();
37
39
38
- int level = Status .INFO ;
40
+ final AtomicInteger level = new AtomicInteger ( Status .INFO ) ;
39
41
40
42
// protected access was requested in http://jira.qos.ch/browse/LBCORE-36
41
43
final protected List <StatusListener > statusListenerList = new ArrayList <StatusListener >();
@@ -57,10 +59,15 @@ public void add(Status newStatus) {
57
59
// LBCORE-72: fire event before the count check
58
60
fireStatusAddEvent (newStatus );
59
61
60
- count ++;
61
- if (newStatus .getLevel () > level ) {
62
- level = newStatus .getLevel ();
63
- }
62
+ count .increment ();
63
+ int newLevel = newStatus .getLevel ();
64
+ int currentLevel ;
65
+ do {
66
+ currentLevel = level .get ();
67
+ if (newLevel <= currentLevel ) {
68
+ break ;
69
+ }
70
+ } while (!level .compareAndSet (currentLevel , newLevel ));
64
71
65
72
synchronized (statusListLock ) {
66
73
if (statusList .size () < MAX_HEADER_COUNT ) {
@@ -90,18 +97,18 @@ private void fireStatusAddEvent(Status status) {
90
97
91
98
public void clear () {
92
99
synchronized (statusListLock ) {
93
- count = 0 ;
100
+ count . reset () ;
94
101
statusList .clear ();
95
102
tailBuffer .clear ();
96
103
}
97
104
}
98
105
99
106
public int getLevel () {
100
- return level ;
107
+ return level . get () ;
101
108
}
102
109
103
110
public int getCount () {
104
- return count ;
111
+ return count . intValue () ;
105
112
}
106
113
107
114
/**
0 commit comments