Execution of new thread inside a synchronized block

后端 未结 2 1300
生来不讨喜
生来不讨喜 2021-01-04 04:54

If i create a new thread inside a synchronized block, will the block remain locked till the thread execution is also complete? If not, then till when would it remain locked

2条回答
  •  感情败类
    2021-01-04 05:46

    It would only remained locked if the code join()d with the newly created thread, thus waiting for it to finish. As there is no join() the lock will be released after the call to start() has completed.

提交回复
热议问题