当前位置:网站首页>线程类的几大创建方法
线程类的几大创建方法
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 "子线程四号开始跑动";
}
}边栏推荐
- 2022 Shanghai safety officer C certificate examination question simulation examination question bank and answers
- STM32 光敏电阻传感器&两路AD采集
- LeetCode_35(搜索插入位置)
- Measurement of quadrature axis and direct axis inductance of three-phase permanent magnet synchronous motor
- Strategic suggestions and future development trend of global and Chinese vibration isolator market investment report 2022 Edition
- 测量三相永磁同步电机的交轴直轴电感
- Day 52 - tree problem
- 2022 t elevator repair question bank and simulation test
- I also gave you the MySQL interview questions of Boda factory. If you need to come in and take your own
- [difficult] sqlserver2008r2, can you recover only some files when recovering the database?
猜你喜欢

分布式全局唯一ID解决方案详解

The design points of voice dialogue system and the importance of multi round dialogue

Maixll dock quick start
![[pat (basic level) practice] - [simple simulation] 1064 friends](/img/37/0ef0f8aae15ae574be1d76c97497c9.jpg)
[pat (basic level) practice] - [simple simulation] 1064 friends

数据加载及预处理

测量三相永磁同步电机的交轴直轴电感

Dual Contrastive Learning: Text Classification via Label-Aware Data Augmentation 阅读笔记

VR线上展览所具备应用及特色

Fitness without equipment

STM32扩展版 按键扫描
随机推荐
Some tools that research dogs may need
Pytorch(四) —— 可视化工具 Visdom
Thoughts on the construction of Meizhou cell room
神经网络-卷积层
Registration for R2 mobile pressure vessel filling test in 2022 and R2 mobile pressure vessel filling free test questions
[FTP] the solution to "227 entering passive mode" during FTP connection
LeetCode_ 35 (search insertion position)
About the transmission pipeline of stage in spark
Dataloader的使用
The design points of voice dialogue system and the importance of multi round dialogue
How to use common datasets in pytorch
Summary of testing experience - Testing Theory
Talk about testdeploy
PR 2021 quick start tutorial, learn about the and functions of the timeline panel
[pat (basic level) practice] - [simple simulation] 1064 friends
LM小型可编程控制器软件(基于CoDeSys)笔记二十:plc通过驱动器控制步进电机
This sideline workload is small, 10-15k, free unlimited massage
Collect the annual summary of laws, regulations, policies and plans related to trusted computing of large market points (national, ministerial, provincial and municipal)
Question bank and answers for chemical automation control instrument operation certificate examination in 2022
总结全了,低代码还需要解决这4点问题