Create threads in java to run in background

后端 未结 3 1414
误落风尘
误落风尘 2020-11-30 01:57

I want to spawn a Java thread from my main java program and that thread should execute separately without interfering with the main program. Here is how it should be:

<
3条回答
  •  感动是毒
    2020-11-30 02:32

    This is another way of creating a thread using an anonymous inner class.

        public class AnonThread {
            public static void main(String[] args) {
                System.out.println("Main thread");
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                    System.out.println("Inner Thread");
                    }
                }).start();
            }
        }
    

提交回复
热议问题