如何使用java调用线程?

Oss*_*ama -3 java multithreading

我想调用一个线程来执行一些代码然后在完成后死掉,在java中执行此操作的最佳方法是什么?

所以例如.

public void update_labels() throws Exception{

...
call the thread from here, obviously non blocking

...
}
Run Code Online (Sandbox Code Playgroud)

线程将连接到数据库并获取/返回一些变量然后终止

roc*_*boy 5

有多种方法可以做到这一点.但如果你的要求就像你说的那么简单那么简单:

new Thread(new Runnable() {
    public void run() {
        //your task
    }
}).start();
Run Code Online (Sandbox Code Playgroud)

会做.

另外,教程