Realm Java and Asynchronous Threading: Frozen Object State Synchronization
26.5K reputation · 02 Mar 2022, 17:04 UTC
Integrating Realm Java with an asynchronous threading model requires managing the boundary between thread-confined live objects and thread-safe frozen objects. While frozen objects allow read access across different threads without triggering an IllegalStateException, they represent a snapshot of the data at a specific point in time.
The challenge arises when a background worker thread performs a writeAsync operation to update a record that is currently being observed as a frozen object on the UI thread. Because frozen objects do not automatically update to reflect changes made in subsequent transactions, the UI state may diverge from the persisted disk state until a new frozen snapshot is explicitly obtained.
- How can the Realm notification system be leveraged to trigger a refresh of frozen objects on the UI thread immediately after a background write completes?
- What is the most efficient mechanism to transition a frozen object back into a live object for a specific update transaction without redundant primary key lookups?