MINOR: Replace synchronization with atomic update in Connect's StateTracker::changeState method (#13934)

Reviewers: Chris Egerton <chrise@aiven.io>
This commit is contained in:
Yash Mayya 2023-06-29 20:05:06 +01:00 committed by GitHub
parent a81f35c1c8
commit 32bcdac6a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 6 deletions

View File

@ -30,16 +30,12 @@ public class StateTracker {
/**
* Change the current state.
* <p>
* This method is synchronized to ensure that all state changes are captured correctly and in the same order.
* Synchronization is acceptable since it is assumed that state changes will be relatively infrequent.
*
* @param newState the current state; may not be null
* @param now the current time in milliseconds
*/
public synchronized void changeState(State newState, long now) {
// JDK8: remove synchronization by using lastState.getAndUpdate(oldState->oldState.newState(newState, now));
lastState.set(lastState.get().newState(newState, now));
public void changeState(State newState, long now) {
lastState.getAndUpdate(oldState -> oldState.newState(newState, now));
}
/**