|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2020 the original author or authors. |
| 2 | + * Copyright 2002-2021 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
16 | 16 |
|
17 | 17 | package org.springframework.core.metrics.jfr;
|
18 | 18 |
|
19 |
| -import java.util.ArrayDeque; |
20 | 19 | import java.util.Deque;
|
| 20 | +import java.util.concurrent.ConcurrentLinkedDeque; |
| 21 | +import java.util.concurrent.atomic.AtomicLong; |
21 | 22 |
|
22 | 23 | import org.springframework.core.metrics.ApplicationStartup;
|
23 | 24 | import org.springframework.core.metrics.StartupStep;
|
|
37 | 38 | */
|
38 | 39 | public class FlightRecorderApplicationStartup implements ApplicationStartup {
|
39 | 40 |
|
40 |
| - private long currentSequenceId; |
| 41 | + private final AtomicLong currentSequenceId = new AtomicLong(0); |
41 | 42 |
|
42 | 43 | private final Deque<Long> currentSteps;
|
43 | 44 |
|
44 | 45 |
|
45 | 46 | public FlightRecorderApplicationStartup() {
|
46 |
| - this.currentSequenceId = 0; |
47 |
| - this.currentSteps = new ArrayDeque<>(); |
48 |
| - this.currentSteps.offerFirst(0L); |
| 47 | + this.currentSteps = new ConcurrentLinkedDeque<>(); |
| 48 | + this.currentSteps.offerFirst(this.currentSequenceId.get()); |
49 | 49 | }
|
50 | 50 |
|
51 | 51 |
|
52 | 52 | @Override
|
53 | 53 | public StartupStep start(String name) {
|
54 |
| - FlightRecorderStartupStep step = new FlightRecorderStartupStep(++this.currentSequenceId, name, |
55 |
| - this.currentSteps.getFirst(), committedStep -> this.currentSteps.removeFirst()); |
56 |
| - this.currentSteps.offerFirst(this.currentSequenceId); |
57 |
| - return step; |
| 54 | + long sequenceId = this.currentSequenceId.incrementAndGet(); |
| 55 | + this.currentSteps.offerFirst(sequenceId); |
| 56 | + return new FlightRecorderStartupStep(sequenceId, name, |
| 57 | + this.currentSteps.getFirst(), committedStep -> this.currentSteps.removeFirstOccurrence(sequenceId)); |
58 | 58 | }
|
59 | 59 |
|
60 | 60 | }
|
0 commit comments