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:
- Main program initiated by the user
- Does some business work and should create a new thread that could handle the background process
- As soon as the thread is created, the main program shouldn’t wait till the spawned thread completes. In fact it should be seamless..
One straight-forward way is to manually spawn the thread yourself:
Alternatively, if you need to spawn more than one thread or need to do it repeatedly, you can use the higher level concurrent API and an executor service: