Skip to content

Commit 5204d73

Browse files
committed
Return static DefaultApplicationStartup step
This commit ensures that `DefaultApplicationStartup` returns a static step for each call to avoid allocations. Closes gh-26939
1 parent e069033 commit 5204d73

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

spring-core/src/main/java/org/springframework/core/metrics/DefaultApplicationStartup.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,16 +29,16 @@
2929
*/
3030
class DefaultApplicationStartup implements ApplicationStartup {
3131

32+
private static final DefaultStartupStep DEFAULT_STARTUP_STEP = new DefaultStartupStep();
33+
3234
@Override
3335
public DefaultStartupStep start(String name) {
34-
return new DefaultStartupStep();
36+
return DEFAULT_STARTUP_STEP;
3537
}
3638

3739

3840
static class DefaultStartupStep implements StartupStep {
3941

40-
boolean recorded = false;
41-
4242
private final DefaultTags TAGS = new DefaultTags();
4343

4444
@Override
@@ -63,23 +63,17 @@ public Tags getTags() {
6363

6464
@Override
6565
public StartupStep tag(String key, String value) {
66-
if (this.recorded) {
67-
throw new IllegalArgumentException();
68-
}
6966
return this;
7067
}
7168

7269
@Override
7370
public StartupStep tag(String key, Supplier<String> value) {
74-
if (this.recorded) {
75-
throw new IllegalArgumentException();
76-
}
7771
return this;
7872
}
7973

8074
@Override
8175
public void end() {
82-
this.recorded = true;
76+
8377
}
8478

8579

0 commit comments

Comments
 (0)