How does Thread.sleep() work when called from multiple threads

后端 未结 5 1952
暖寄归人
暖寄归人 2021-01-18 05:31

sleep() is a static method of class Thread. How does it work when called from multiple threads. and how does it figure out the current thread of execution. ?

or may

5条回答
  •  醉酒成梦
    2021-01-18 05:40

    a more generic Question would be How are static methods called from different threads ? Won't there be any concurrency problems ?

    There is only a potential concurrency problem if one or more thread modifies shared state while another thread uses the same state. There is no shared state for the sleep() method.

提交回复
热议问题