Java threads and synchronized blocks

前端 未结 3 584
心在旅途
心在旅途 2021-02-14 18:09

Suppose I\'m executing a synchronized block of code inside some thread and within the synchronized block I call a method that spawns another thread to

3条回答
  •  清酒与你
    2021-02-14 18:32

    There's nothing wrong about this code. Before the return statement in someOtherMethod(), the code is running in the synchronized block of someMethod(). After the new thread starts, it will block on the synchronized statement inside the run() method until it obtains a lock on lock_obj (at the earliest, whenever someMethod() exits its synchronized block).

提交回复
热议问题