java線程和線程池

java線程兩種形式

  • 這個是正常的Thread
Thread thread2 = new Thread(threadGroup, new Runnable() {
            public void run() {
                //do something.
            }
        }, "No.2");
        thread2.start();

-這個是Future方式 FutureTask<String> futureTask = new FutureTask<String>(new Callable<String>() { public String call() throws Exception { TimeUnit.SECONDS.sleep(5); return "game over!";java

}
    });


    new Thread(futureTask).start();


    System.out.println(futureTask.isDone());
    System.out.println(futureTask.get());

#java線程池線程

相關文章
相關標籤/搜索