当前位置:网站首页>创建多线程的方法---1创建Thread类的子类及多线程原理
创建多线程的方法---1创建Thread类的子类及多线程原理
2022-06-28 09:21:00 【用户9857551】
创建多线程的方法
创建多线程的第一种方式:创建Thread类的子类 Java.lang.Thread类:是描述线程的类,我们想要实现多线程程序,就必须继承Thread类。 实现步骤: 1.创建一个Thread类的子类。 2.在Thread类的子类中的run方法,设置线程任务(开启线程要做什么)。 3.创建Thread类的子类对象。 4.调用Thread类中的方法start()方法,执行run方法。 void start()使用该线程开始执行,Java虚拟机调用该线程的run方法。 结果是两个线程并发运行,当前线程(main线程;也叫主线程)和另一个线程(创建新的线程,执行其run方法)。 多次启动一个线程是非法的。特别是当线程已经结束执行后,不能再重新启动。 Java程序是抢占式调度,哪个线程优先级高 先执行哪个,同一个优先级随机选一个执行。 示例:
主方法:
结果:两个线程在抢占CPU执行时间。
多线程随机打印原理:
边栏推荐
- Deployment of MySQL database in Linux Environment
- SQL 優化經曆:從 30248秒到 0.001秒的經曆
- Common test method used by testers --- orthogonal method
- Android studio interview preparation
- Use of Jasper soft studio report tool and solution of thorny problems
- 01-分布式系统概述
- [ybtoj advanced training guide] maximum separation [hash] [Floyd]
- 剑指Offer | 斐波那契数列
- 硬盘基本知识(磁头、磁道、扇区、柱面)
- 详解final、finally和finalize
猜你喜欢

图解MySQL的binlog、redo log和undo log

Fire fighting work and measures in Higher Vocational Colleges

This article explains in detail the difficult problems and solutions faced by 3D cameras

虚拟机14安装win7(图教程)

从知识到智慧:知识图谱还要走多远?

DEJA_ Vu3d - 051 of cesium function set - perfect realization of terrain excavation

Postman interface test

Expérience d'optimisation SQL: de 30248 secondes à 0001 secondes
理解IO模型
![1180:分数线划定/P1068 [NOIP2009 普及组] 分数线划定](/img/1a/162b060a6498e58278b6ca50e4953c.png)
1180:分数线划定/P1068 [NOIP2009 普及组] 分数线划定
随机推荐
自动转换之-面试题
DEJA_ Vu3d - 052 of cesium feature set - Simulation of satellite orbit (high altitude) effect
Do static code blocks always execute first? The pattern is smaller!!!
1. Kimball dimension modeling of data warehouse: what is a fact table?
For the development of short video app, the elder warned me to choose the open source code
1182: group photo effect
Deployment of MySQL database in Linux Environment
Loggerfactory uses log4j Parameter introduction of properties
Boundary value analysis method for learning basic content of software testing (2)
new URL(“www.jjj.com“)
DEJA_VU3D - Cesium功能集 之 051-地形开挖完美实现
详解final、finally和finalize
How to solve the problem of port number occupation
Fastjason filter field
玩玩sftp上传文件
当面试官让你用两种方式写BinarySort
What is online account opening? Is it safe to open an account online now?
Ingersoll Rand panel maintenance IR Ingersoll Rand microcomputer controller maintenance xe-145m
手机买同业存单基金开户选哪家证券公司比较好,比较安全呢
Use of Jasper soft studio report tool and solution of thorny problems