Jérémy CROS
01/11/2023, 4:19 PMprivate val mutableListOf()
and the code that crashes just .add
to that list.
Exception is: ArrayIndexOutOfBoundsException
We’re not sure what the issue could be, only idea that comes to mind is 2 threads calling add at the same time.
• Anything else worth investigating?
• If it’s the most likely issue, is there a solution beside “dont call twice on different threads”
• Something like a thread safe list maybe?
Thanks! 🙏Sam
01/11/2023, 4:22 PMSam
01/11/2023, 4:22 PMCollections.synchronizedList
from JavaJérémy CROS
01/11/2023, 4:48 PMMichael de Kaste
01/11/2023, 4:56 PMsynchronized(listToAddTo) {
listToAddTo.add(thingYouAreAdding)
}
Sam
01/11/2023, 4:56 PMCopyOnWriteArrayList
and LinkedBlockingQueue
Kristian Nedrevold
01/11/2023, 7:45 PMKristian Nedrevold
01/11/2023, 7:47 PMKevin Del Castillo
01/11/2023, 8:57 PMJérémy CROS
01/12/2023, 8:31 AMprivate val myList = mutableListOf<Data>()
fun logData(data: Data) {
myList.add(data)
}
Becomes:
private val myList = mutableListOf<Data>()
private val mutex = Mutex()
suspend fun logData(data: Data) {
mutex.withLock {
myList.add(data)
}
}
Correct?