Skip to content

Instantly share code, notes, and snippets.

@smyykb
Created January 8, 2018 12:36
Show Gist options
  • Save smyykb/d064e29eb69c7b74e0e583918080088b to your computer and use it in GitHub Desktop.
Save smyykb/d064e29eb69c7b74e0e583918080088b to your computer and use it in GitHub Desktop.
commit() writes the data synchronously (blocking the thread its called from). It then informs you about the success of the operation.
apply() schedules the data to be written asynchronously. It does not inform you about the success of the operation.
If you save with apply() and immediately read via any getX-method, the new value will be returned!
If you called apply() at some point and it's still executing, any calls to commit() will block until all apply-calls and its own commit are finished.
commit() writes its data to persistent storage immediately, whereas apply() will handle it in the background.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment