How do I start a background thread that does not block the main java thread?

I have the following java code:

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

My problem is that starting myrunnable will block the main thread, so that showgui will not be called until it finishes running What I want the program to do is to generate myrunnable and allow it to run independently in the background, so that the main thread can forget it and continue to do what it wants to do (such as calling showgui)

Solution

Run executes on the main thread Start creates a new thread and executes its run method on that thread

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>