当前位置:网站首页>Several methods of creating thread classes
Several methods of creating thread classes
2022-07-01 04:48:00 【Yangasang 815】
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
public class Test1 {
public static void main(String[] args) throws Exception {
// Create method 1 Create thread class inheritance Thread class
MyThread m1=new MyThread();
m1.start();
// Create a thread method 2; Create a thread task class MyRunable Realization Runable Interface take Runable Object to Thread Handle
MyRunable m2=new MyRunable();
Thread mm2=new Thread(m2);
mm2.start();
// establish Runable Anonymous inner class objects are given to Thread
Runnable runnable=new Runnable() {
@Override
public void run() {
System.out.println(" Sub thread 3 starts running ");
}
};
new Thread(runnable).start();
// Method 3 : utilize Callable And FutureTask Interface implementation
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(" Sub thread 1 starts running ");
}
}
class MyRunable implements Runnable{
@Override
public void run() {
System.out.println(" Sub thread 2 starts running ");
}
}
class MyCallable implements Callable{
@Override
public Object call() throws Exception {
return " Sub thread 4 starts running ";
}
}边栏推荐
- 科研狗可能需要的一些工具
- Pytorch(一) —— 基本语法
- C#读写应用程序配置文件App.exe.config,并在界面上显示
- Common methods in transforms
- Some tools that research dogs may need
- [hardware ten treasures catalogue] - reprinted from "hardware 100000 whys" (under continuous update ~ ~)
- 最长递增子序列及最优解、动物总重量问题
- [daily question in summer] first time, second time, deal!
- 【暑期每日一题】洛谷 P7222 [RC-04] 信息学竞赛
- Technology sharing | broadcast function design in integrated dispatching
猜你喜欢

Oracle views the creation time of the tablespace in the database

Sorting out 49 reports of knowledge map industry conference | AI sees the future with wisdom

神经网络-使用Sequential搭建神经网络

About the transmission pipeline of stage in spark
![解决:Thread 1:[<*>setValue:forUndefinedKey]:this class is not key value coding-compliant for the key *](/img/88/0b99d1db2cdc70ab72d2b3c623dfaa.jpg)
解决:Thread 1:[<*>setValue:forUndefinedKey]:this class is not key value coding-compliant for the key *

Why is Internet thinking not suitable for AI products?

Applications and features of VR online exhibition

技术分享| 融合调度中的广播功能设计

分布式全局唯一ID解决方案详解
![[2020 overview] overview of link prediction based on knowledge map embedding](/img/69/22983c5f37bb67a8dc0e2b87c73238.jpg)
[2020 overview] overview of link prediction based on knowledge map embedding
随机推荐
Difficulties in the development of knowledge map & the importance of building industry knowledge map
Cmake selecting compilers and setting compiler options
线程安全问题
【暑期每日一题】洛谷 P1568 赛跑
Dual contractual learning: text classification via label aware data augmentation reading notes
[FTP] the solution to "227 entering passive mode" during FTP connection
【暑期每日一题】洛谷 P2026 求一次函数解析式
Kodori tree board
【FTP】FTP常用命令,持续更新中……
Leecode records the number of good segmentation of 1525 strings
Summary of acl2021 information extraction related papers
[une question par jour pendant l'été] course luogu p1568
JVM栈和堆简介
Pytoch (I) -- basic grammar
Difference between cookie and session
Design experience of Meizhou clinical laboratory
[pat (basic level) practice] - [simple simulation] 1064 friends
Construction of Meizhou nursing laboratory: equipment configuration
AssertionError assert I.ndim == 4 and I.shape[1] == 3
Extension fragment