Skip to content

Commit

Permalink
MINOR: Replace synchronization with atomic update in Connect's StateT…
Browse files Browse the repository at this point in the history
…racker::changeState method (apache#13934)

Reviewers: Chris Egerton <chrise@aiven.io>
  • Loading branch information
yashmayya authored and C0urante committed Jun 29, 2023
1 parent 041afb7 commit 879de5a
Showing 1 changed file with 2 additions and 6 deletions.
Expand Up @@ -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));
}

/**
Expand Down

0 comments on commit 879de5a

Please sign in to comment.