android / architecture-components-samples

Samples for Android Architecture Components.
https://d.android.com/arch
Apache License 2.0
23.4k stars 8.29k forks source link

BasicSample AppDatabase volatile #882

Open squm opened 4 years ago

squm commented 4 years ago

https://github.com/android/architecture-components-samples/blob/1816deaa2f2f087cc16c5cd4199c7600395b9905/BasicSample/app/src/main/java/com/example/android/persistence/db/AppDatabase.java#L44

Hello, I am looking at the “Android Room with a View - Java” and they declare database instance as volatile

    // marking the instance as volatile to ensure atomic access to the variable
    private static volatile WordRoomDatabase INSTANCE;