Hi Colton,
just out of curiosity, where is your log data stored when
LogFlusher
doesn't have state?
Now to your question: as always with concurrency, there are a lot of options 😅 Since your
LogFlusher
isn't a singleton I would refrain from using the
@Synchronized
annotation but rather the function with the class itself as a lock:
fun flush() {
synchronized(LogFlusher::class){
...
}
}
That ways you should be safe on a class level. Alternatively, you could also use a static
Semaphore
or
Mutex
and block access inside the method to a single thread.