java创建线程的几种方式
2021-02-02 13:15
标签:实现 return art bug except override exception 接口 ret 1.创建Thread对象 并实现run方法 java创建线程的几种方式 标签:实现 return art bug except override exception 接口 ret 原文地址:https://www.cnblogs.com/mc-74120/p/12810617.htmlThread thread=new Thread(){
@Override
public void run() {
super.run();
log.debug("running");
}
};
thread.start();
2.实现Runnable接口并把该对象作为参数传给Thread对象Runnable runnable=new Runnable() {
@Override
public void run() {
System.out.println(120);
}
};
Thread thread=new Thread(runnable);
3.FutureTask
@Override
public Integer call() throws Exception {
Thread.sleep(5000);
System.out.println(1111111);
return 100;
}
});
Thread thread=new Thread(futureTask);
thread.start();
System.out.println(futureTask.get());