Why is this thread affecting the main thread?

前端 未结 2 1381
南旧
南旧 2020-12-19 20:43

I must be missing something:

public class Test {
    public static void main(String[] args) {
        (new Thread(new Action())).run();
        System.out.pr         


        
2条回答
  •  没有蜡笔的小新
    2020-12-19 20:53

    Because you are not invoking start(), you are calling directly the implementation method of the thread run(), thus no thread is started, code is just executed.

    run() is the method called by the thread internal structure to execute the task, since it's just a normal method which doesn't have anything attached.

提交回复
热议问题