Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve org.springframework.util.StopWatch [SPR-13509] #18087

Closed
spring-projects-issues opened this issue Sep 25, 2015 · 1 comment
Closed

Improve org.springframework.util.StopWatch [SPR-13509] #18087

spring-projects-issues opened this issue Sep 25, 2015 · 1 comment
Assignees
Labels
in: core type: enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Sep 25, 2015

Thomas Escolan opened SPR-13509 and commented

  • The currentTaskName field is private (final) without a getter
    The running task's name cannot be retrieved unless stop is called.
    WORKAROUND
StopWatch sw = new StopWatch();
try {
     Field f = StopWatch.class.getDeclaredField("currentTaskName");
     f.setAccessible(true);  // I'm a hacker!
     String taskname = f.get(sw);
} catch (NoSuchFieldException | IllegalAccessException e) {
     throw new IllegalStateException(e);
}
  • The start method runs init actions AFTER storing timestamp
    ILLUSTRATION
public void start(String taskName) throws IllegalStateException {
     if (this.running) {
          throw new IllegalStateException("Can't start StopWatch: it's already running");
     }
     this.startTimeMillis = System.currentTimeMillis();  // to be done last...
     this.running = true;
     this.currentTaskName = taskName;
     // ... there ; in order not to take inits above into account
}

Affects: 4.1.7

Referenced from: commits a6a6aed

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 25, 2015

Juergen Hoeller commented

Good points... rolled into 4.2.2 now.

Juergen

@spring-projects-issues spring-projects-issues added type: enhancement in: core labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 4.2.2 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants