how to override thread.start() method in java?

前端 未结 10 1820
情歌与酒
情歌与酒 2020-12-03 02:07

I need to implement thread.start() method in my java code. Please let me know through an example of overriding of thread.start() method and how it works?

10条回答
  •  执笔经年
    2020-12-03 02:54

    Actually, you can call run() to run a thread instead of start() to run a thread. But there is a little difference.

    Suppose you create two threads:

    Thread t1 = new Thread();
    Thread t2 = new Thread();
    

    Case 1 : If you call "t1.run()" and "t2.run()" one after another they will start to run t1 and t2 synchronously (sequentially).

    Case 2 : If you call "t1.start()" and "t2.start()" one after another they will call their run() methods and start to run t1 and t2 asynchronously (in parallel).

提交回复
热议问题