What does synchronized do in this section?

Viewed 53

I do not understand exactly what synchronized does in this code

fun getDatabase(context: Context): UserDatabase{
        val tempInstance = INSTANCE
        if(tempInstance != null){
            return tempInstance
        }
        synchronized(this){
            val instance = Room.databaseBuilder(
                context.applicationContext,
                UserDatabase::class.java, "user_database"
            ).build()
            INSTANCE = instance
            return instance
0 Answers
Related