Why can't we call the start method twice on a same instance of the Thread object?

后端 未结 5 1453
孤街浪徒
孤街浪徒 2020-12-03 03:16

I was reading about threads and found that we can\'t call the start method twice on the same thread instance. But I didn\'t understand the exact reason for the same. So why

5条回答
  •  旧时难觅i
    2020-12-03 04:00

    In my opinion the Thread object is your "handle" for the actual running context. If you allow creating many concurrent executions associated with the same java.lang.Thread, what would you expect getStackTrace() and getState() methods to return?

    I suppose that Thread class could have been designed to allow spawning multiple running contexts, but its API would be less simple and clean.

提交回复
热议问题