How to start a background thread that doesn't block the main thread in Java?

blocking, concurrency, java, multithreading, runnable

Solution

`run` executes on the main thread. `start` will create a new thread execution and execute it's run method on that thread.

Problem

I have the following Java code: ``` public static void main(String[] args) { new Thread(new MyRunnable()).run(); showGUI(); } ``` My problem is that starting `MyRunnable` blocks the main thread, causing `showGUI` to not be called until it finishes running. What I'd like the program to do is spawn `MyRunnable` and allow it to run independently in the background, enabling the main thread to forget about it and go ahead and do what it wants (like call `showGUI`).

Original source