Does scala support synchronized object (/static) methods? I am looking for:
synchronized def myObjectMethod(): <SomeReturnType> = {
..
}
If this were not supported, what is the equivalent in scala ?
Does scala support synchronized object (/static) methods? I am looking for:
synchronized def myObjectMethod(): <SomeReturnType> = {
..
}
If this were not supported, what is the equivalent in scala ?
synchronized
in scala is just a method1. So you can do
def myObjectMethod: SomeReturnType = synchronized {
// stuff
}
It's actually a special method injected by the compiler, more details here: How is the synchronized method on AnyRef implemented?
synchronized
synchronize with this
? So if I have def foo = synchronized{ /* stuff */}; def bar = synchronized{ /* other stuff */ }
, will I be able to run the two concurrently (i.e., foo
and bar
can run at same time but one at most copy of each) –
Healy © 2022 - 2024 — McMap. All rights reserved.