当前位置:网站首页>Methods for creating multithreads ---1 creating subclasses of thread class and multithreading principle
Methods for creating multithreads ---1 creating subclasses of thread class and multithreading principle
2022-06-28 09:25:00 【User 9857551】
Method of creating multithreading
The first way to create multithreading : establish Thread Subclasses of classes Java.lang.Thread class : Is a class that describes threads , We want to implement multithreaded programs , Must inherit Thread class . Implementation steps : 1. Create a Thread Subclasses of classes . 2. stay Thread In a subclass of class run Method , Set up thread tasks ( What does the thread do ). 3. establish Thread Subclass object of class . 4. call Thread Methods in class start() Method , perform run Method . void start() Use this thread to start execution ,Java The virtual machine calls the thread's run Method . The result is two threads running concurrently , Current thread (main Threads ; Also called main thread ) And another thread ( Create a new thread , To perform its run Method ). It's illegal to start a thread multiple times . Especially when the thread has finished executing , Can't restart again . Java The program is preemptive scheduling , Which thread has the highest priority Which one to execute first , Select one at random for the same priority . Example :
Main method :
result : Two threads are preempting CPU execution time .
Multi thread random printing principle :
边栏推荐
- From knowledge to wisdom: how far will the knowledge map go?
- Screen settings in the source code of OBS Live Room
- 静态代码块永远先执行? 格局小了!!!
- The Cassandra cluster reinstalls and starts from the node. An error is reported. There is an existing solution
- HDI的盲孔设计,你注意到这个细节了吗?
- DEJA_ Vu3d - 051 of cesium function set - perfect realization of terrain excavation
- PMP needs to master its own learning methods
- Music website design based on harmonyos (portal page)
- Understanding the IO model
- PMP考试重点总结七——监控过程组(1)
猜你喜欢

全局异常处理器与统一返回结果

Chrome devtools

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

Redis5.0 slot migration, free play (single machine migration cluster)

DolphinScheduler使用系统时间

From knowledge to wisdom: how far will the knowledge map go?

How to reduce the risk of project communication?

The concept of "tree structure" perfectly interprets the primary and secondary of things

Why does select * lead to low query efficiency?

买卖股票费用计算
随机推荐
剑指Offer | 斐波那契数列
多线程-并发并行-线程进程
The Cassandra cluster reinstalls and starts from the node. An error is reported. There is an existing solution
Fastjason filter field
redis5.0的槽点迁移,随意玩(单机迁移集群)
Automatic conversion - interview questions
静态代码块永远先执行? 格局小了!!!
Illustration of MySQL binlog, redo log and undo log
Resource scheduling and task scheduling of spark
01-分布式系统概述
JVM系列(2)——垃圾回收
Linux下安装redis 、Windows下安装redis(超详细图文教程)
Why does select * lead to low query efficiency?
Scenario method and error recommendation method for learning basic content of software testing (2)
English translation plug-in installation of idea
RMAN backup message ora-19809 ora-19804
How to reduce the risk of project communication?
Decision table method for basic content learning of software testing (2)
new URL(“www.jjj.com“)
学习阿里如何进行数据指标体系的治理