Is method synchronization equivalent, allowing only one thread to evaluate it until it is removed from the scope, including calls to internal methods?
For instance:
public synchronized void foo(){ if(critical condition){ bar(); // can influence the above condition } baz(); // can influence the above condition }
Could two threads be in bar(suppose it is called only from here)?
bar
What if bazone can call from a different place in the code other than foo, can two threads in it?
baz
foo
This is the equivalent way to write code:
public void foo(){ synchronized (this) { if(critical condition){ bar(); // can influence the above condition } baz(); // can influence the above condition } }
this .
this
, foo() bar()? , foo() bar() .
foo()
bar()
, baz() , baz() , foo().
baz()
, Java:
, , , . :
(, )?
, , - wait() ing.
wait()
, baz , foo, ?
, synchronized , .
synchronized
Source: https://habr.com/ru/post/1657913/More articles:How to get materializable fixed action button working in angular 2 - javascriptWhen to use or how to use multiple bindings in generics - javaMeta.fields contains a field that is not defined on this FilterSet: **** - djangoКак я могу передавать данные с экспресс-сервера, чтобы реагировать на представления? - node.jsDjango Rest Framework filters calculated model property - djangoWhen can I call onTaskRemoved ()? - androidAndroid Galaxy S3 stopped installing mtp for debian testing - androidКак вызвать неэксклюзивное закрытие внутри локального закрытия? - closuresGet invalid value from input type number - javascriptEntity Framework circular dependency for the last object - entity-frameworkAll Articles