一种简单的方法是自己手动生成线程:
public static void main(String[] args) { Runnable r = new Runnable() { public void run() { runYourBackgroundTaskHere(); } }; new Thread(r).start(); //this line will execute immediately, not waiting for your task to complete}另外,如果您需要产生多个线程或需要重复执行,则可以使用更高级别的并发API和执行程序服务:
public static void main(String[] args) { Runnable r = new Runnable() { public void run() { runYourBackgroundTaskHere(); } }; ExecutorService executor = Executors.newCachedThreadPool(); executor.submit(r); // this line will execute immediately, not waiting for your task to complete executor.shutDown(); // tell executor no more work is coming // this line will also execute without waiting for the task to finish }


