Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
49858a0f
Commit
49858a0f
authored
Dec 01, 2014
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix concurrent gaugeLocks map access
Use putIfAbsent to ensure atomic creation of lock objects. Fixes gh-1995
parent
ffe53480
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
10 deletions
+10
-10
CodahaleMetricWriter.java
...ork/boot/actuate/metrics/writer/CodahaleMetricWriter.java
+10
-10
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/writer/CodahaleMetricWriter.java
View file @
49858a0f
...
@@ -90,25 +90,25 @@ public class CodahaleMetricWriter implements MetricWriter {
...
@@ -90,25 +90,25 @@ public class CodahaleMetricWriter implements MetricWriter {
}
}
else
{
else
{
final
double
gauge
=
value
.
getValue
().
doubleValue
();
final
double
gauge
=
value
.
getValue
().
doubleValue
();
Object
lock
=
null
;
if
(
this
.
gaugeLocks
.
containsKey
(
name
))
{
lock
=
this
.
gaugeLocks
.
get
(
name
);
}
else
{
this
.
gaugeLocks
.
putIfAbsent
(
name
,
new
Object
());
lock
=
this
.
gaugeLocks
.
get
(
name
);
}
// Ensure we synchronize to avoid another thread pre-empting this thread after
// Ensure we synchronize to avoid another thread pre-empting this thread after
// remove causing an error in CodaHale metrics
// remove causing an error in CodaHale metrics
// NOTE: CodaHale provides no way to do this atomically
// NOTE: CodaHale provides no way to do this atomically
synchronized
(
lock
)
{
synchronized
(
getGuageLock
(
name
)
)
{
this
.
registry
.
remove
(
name
);
this
.
registry
.
remove
(
name
);
this
.
registry
.
register
(
name
,
new
SimpleGauge
(
gauge
));
this
.
registry
.
register
(
name
,
new
SimpleGauge
(
gauge
));
}
}
}
}
}
}
private
Object
getGuageLock
(
String
name
)
{
Object
lock
=
this
.
gaugeLocks
.
get
(
name
);
if
(
lock
==
null
)
{
this
.
gaugeLocks
.
putIfAbsent
(
name
,
new
Object
());
lock
=
this
.
gaugeLocks
.
get
(
name
);
}
return
lock
;
}
@Override
@Override
public
void
reset
(
String
metricName
)
{
public
void
reset
(
String
metricName
)
{
this
.
registry
.
remove
(
metricName
);
this
.
registry
.
remove
(
metricName
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment