当前位置:网站首页>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 卷积操作

数据加载及预处理

神经网络的基本骨架-nn.Moudle的使用

Pytoch (III) -- function optimization

RuntimeError: “max_pool2d“ not implemented for ‘Long‘

RuntimeError: mean(): input dtype should be either floating point or complex dtypes.Got Long instead

pytorch中常用数据集的使用方法

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

PR 2021 quick start tutorial, learn about the and functions of the timeline panel

Why is Internet thinking not suitable for AI products?
随机推荐
神经网络-使用Sequential搭建神经网络
打印流与System.setout();
C -- array
Neural network convolution layer
[daily question in summer] Luogu p2026 find the analytic formula of primary function
Quelques outils dont les chiens scientifiques pourraient avoir besoin
LeetCode_66(加一)
Take a cold bath
Common methods in transforms
2022 tea master (intermediate) examination question bank and tea master (intermediate) examination questions and analysis
Construction of Meizhou nursing laboratory: equipment configuration
Leecode question brushing record 1310 subarray XOR query
1076 Forwards on Weibo
One click shell to automatically deploy any version of redis
科研狗可能需要的一些工具
Cmake selecting compilers and setting compiler options
[hard ten treasures] - 2 [basic knowledge] characteristics of various topological structures of switching power supply
Difference between cookie and session
【暑期每日一题】洛谷 P5740【深基7.例9】最厉害的学生
无器械健身