Execution order of multiple threads

前端 未结 4 1779
失恋的感觉
失恋的感觉 2020-12-03 16:43

Let\'s say we have this scenario:

class Stack{

public void main{

ChildThread1 t1 = new ChildThread1;
ChildThread1 t2 = new ChildThread1;
ChildThread1 t3 =          


        
4条回答
  •  再見小時候
    2020-12-03 16:53

    So am I right to assume that this weird order of prints is because start() does not guarantee order of execution?

    Yes. You are right.

    Will this reason also apply to 'all threads are ready' problem?

    Yes. Right again. Your SOP is run by main thread. So, it's possible that t1 can print something before main gets chance to execute it's SOP.

提交回复
热议问题