当前位置:网站首页>线程类的几大创建方法
线程类的几大创建方法
2022-07-01 04:46:00 【洋啊桑815】
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
public class Test1 {
public static void main(String[] args) throws Exception {
//创建方法1 创建线程类继承Thread类
MyThread m1=new MyThread();
m1.start();
//创建线程方法2;创建线程任务类MyRunable实现Runable接口 将Runable对象交给Thread处理
MyRunable m2=new MyRunable();
Thread mm2=new Thread(m2);
mm2.start();
//创建Runable匿名内部类对象交给Thread
Runnable runnable=new Runnable() {
@Override
public void run() {
System.out.println("子线程三号开始跑动");
}
};
new Thread(runnable).start();
//方法三:利用Callable与FutureTask接口实现
MyCallable callable=new MyCallable();
FutureTask futureTask=new FutureTask(callable);
new Thread(futureTask).start();
System.out.println(futureTask.get());
}
}
class MyThread extends Thread{
@Override
public void run(){
System.out.println("子线程一号开始跑动");
}
}
class MyRunable implements Runnable{
@Override
public void run() {
System.out.println("子线程二号开始跑动");
}
}
class MyCallable implements Callable{
@Override
public Object call() throws Exception {
return "子线程四号开始跑动";
}
}边栏推荐
- LeetCode_ 28 (implement strstr())
- Why is Internet thinking not suitable for AI products?
- 神经网络的基本骨架-nn.Moudle的使用
- How to use maixll dock
- Codeforces Round #771 (Div. 2) ABCD|E
- LeetCode_ 58 (length of last word)
- pytorch中常用数据集的使用方法
- JS rotation chart
- 科研狗可能需要的一些工具
- Common UNIX Operation and maintenance commands of shell
猜你喜欢

Use of dataloader

分布式-总结列表

Research on medical knowledge atlas question answering system (I)

Odeint and GPU

Question bank and answers for chemical automation control instrument operation certificate examination in 2022

The index is invalid

LM small programmable controller software (based on CoDeSys) note 19: errors do not match the profile of the target

神经网络-卷积层

Why is Internet thinking not suitable for AI products?

Pytorch(三) —— 函数优化
随机推荐
LeetCode_ 35 (search insertion position)
Dataloader的使用
LeetCode_ 58 (length of last word)
神经网络-使用Sequential搭建神经网络
Question bank and answers for chemical automation control instrument operation certificate examination in 2022
Odeint et GPU
神经网络-最大池化的使用
Extension fragment
Summary of testing experience - Testing Theory
LM小型可编程控制器软件(基于CoDeSys)笔记二十:plc通过驱动器控制步进电机
1076 Forwards on Weibo
Use of dataloader
Pytorch(四) —— 可视化工具 Visdom
OdeInt與GPU
Openresty rewrites the location of 302
技术分享| 融合调度中的广播功能设计
The longest increasing subsequence and its optimal solution, total animal weight problem
Applications and features of VR online exhibition
Caijing 365 stock internal reference | the first IPO of Beijing stock exchange; the subsidiary of the recommended securities firm for gambling and gambling, with a 40% discount
总结全了,低代码还需要解决这4点问题