Hey guys. I had that code `@Synchronized` `fun abc...
# android
q
Hey guys. I had that code
@Synchronized
fun abc() {
// do some heavy tasks in multiple threads
}
In the document `@Synchronized`is thread safe annotation but I wonder that Should I use multiple thread operations inside function
abc()
?
g
do some heavy tasks in multiple threads
Syncronized doesn’t work like magic and bring thread safety to your code, it just doesn’t allow multiple threads to access code in this block. But if you launch some kind async operation or thread from this abc method, syncronized will do nothing for thread safety in this case. I would recommend to check articles how JVM synchronized methods work, there is a plenty of blog posts/articles about it
👍 2
q
Thanks