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

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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