当前位置:网站首页>Implement the runnable interface
Implement the runnable interface
2022-06-26 05:59:00 【Mr.Rop】
Realization Runnable Interface
// Create thread 2: Realization Runnable Interface , rewrite run() Method , The execution thread needs to drop runnable Interface implementation class , call start() Method .
public class TestThread3 implements Runnable {
@Override
public void run() {
for (int i = 0; i < 100; i++) {
// run Method thread body
System.out.println(" I'm looking at the code -----" + i);
}
}
public static void main(String[] args) {
// establish Runnable Implementation class object of interface
TestThread3 testThread3 = new TestThread3();
// Create thread , Object starts a thread through a thread object
// Thread thread = new Thread(testThread3);
// thread.start();
new Thread(testThread3).start();
for (int i = 0; i < 1000; i++) {
System.out.println(" I'm learning multithreading -----" + i);
}
}
}
Summary
Inherit Threa class
- A subclass inherits Thread Class has multithreading capabilities
- Start thread : Subclass object .start()
- Not recommended : avoid OOP Limitations of single inheritance
Realization Runnable Interface
- Implementation interface Runnable Multithreading capability
- Start thread : Incoming target object Thread object .start()
- Recommended : Avoid the limitations of single inheritance , Flexible and convenient , It is convenient to unify an object to be used by multiple threads
边栏推荐
- one billion two hundred and twelve million three hundred and twelve thousand three hundred and twenty-one
- 冒泡排序(Bubble Sort)
- 05. basic data type - Dict
- On site commissioning - final method of kb4474419 for win7 x64 installation and vs2017 flash back
- Describe an experiment of Kali ARP in LAN
- Feelings of virtual project failure
- 06. talk about the difference and coding between -is and = = again
- 【 langage c】 stockage des données d'analyse approfondie en mémoire
- 重载和重写
- The model defined (modified) in pytoch loads some required pre training model parameters and freezes them
猜你喜欢

小程序如何关联微信小程序二维码,实现二码聚合

kolla-ansible部署openstack yoga版本

The purpose of writing programs is to solve problems

Cython入门

Record how to modify the control across threads

Prototype mode, Baa Baa

pytorch(网络模型训练)

操作符的优先级、结合性、是否控制求值顺序【详解】

Bubble sort

E-commerce seeks growth breakthrough with the help of small program technology
随机推荐
【 langage c】 stockage des données d'analyse approfondie en mémoire
REUSE_ALV_GRID_DISPLAY 事件实现(DATA_CHANGED)
原型模式,咩咩乱叫
Force buckle 875 Coco, who likes bananas
numpy. log
Definition of Halcon hand eye calibration
Selective Search for Object Recognition 论文笔记【图片目标分割】
Project suspension
About XXX management system (version C)
numpy. tile()
MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications
机器学习 05:非线性支持向量机
Soft power and hard power in program development
Selective search for object recognition paper notes [image object segmentation]
Interface oriented programming
Redis多线程与ACL
自定义WebSerivce作为代理解决SilverLight跨域调用WebService问题
Matching environment of ES6
Func < T, tresult > Commission - learning record
MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications