How to start a background thread that does not block the main thread in Java?

I have the following Java code:

public static void main(String[] args)
{
    new Thread(new MyRunnable()).run();
    showGUI();
}

My problem is that the launch MyRunnableblocks the main thread, causing showGUIit to not be called until it finishes working. I would like the program to create spawn MyRunnableand let it work independently in the background, allowing the main thread to forget about it and go ahead and do what it wants (for example, call showGUI).

+3
source share
2 answers

runexecuted in the main thread. startwill create a new thread execution and execute it on that thread.

+9
source

start() , run().

+5

All Articles