当前位置:网站首页>20220707 线程学习 继承
20220707 线程学习 继承
2022-07-16 22:09:00 【Aboxhhh】
- 不能通过run来启动线程。
- start()1.启动线程2.调用当前线程的run方法
如果直接调用run()方法,相当于没有创建线程 - 一个线程只能用一次start()
/** * @author * @create 2022/7/10 * 创建两个线程其中一个遍历100以内的偶数,另一个遍历奇数 *每次打印出来都不同 * 涉及到CPU的切换 * **/
public class ThreadDemo
{
public static void main(String[] args) {
MyThread2 t1=new MyThread2();
MyThread1 t2= new MyThread1();
t1.start();
t2.start();
}
}
class MyThread1 extends Thread{
@Override
public void run() {
for (int i = 0; i < 100; i++) {
if(i%2==0){
System.out.println(i+Thread.currentThread().getName());
}
}
}
}
class MyThread2 extends Thread{
@Override
public void run() {
for (int i = 0; i < 100; i++) {
if(i%2!=0){
System.out.println(i+Thread.currentThread().getName());
}
}
}
}
边栏推荐
- 每日一题:合并两个排序的链表(剑指offer25)
- nodejs 定义错误验证机制
- In depth explanation of MySQL index
- Hibench generates benchmark data sets [wordcount as an example]
- fiddler抓不到PC端微信小程序的包
- 單行文本 超出部分省略號,多行文本超出部分省略號,指定多行
- 为什么 Nodejs 这么快?
- go+mysql+redis+vue3简单聊室,第5弹:使用消息队列和定时任务同步消息到mysql
- matplotlib.pyplot使用(subplots,gray
- 8. Introduction to JVM optimization
猜你喜欢
随机推荐
Openpose: estimation de la pose 2D Multi - personnes en temps réel à l'aide d'un champ d'affinité partiel
【考试】二阶段2201班考试答案(做错一概不负责)
Shh! Fishing artifact, don't let the boss know| Real time voice to text, fast time sequence prediction, yolov6 can be used in one line of command to sort out CSV | showmeai Information Daily
最大子数组异或和
What should I pay attention to when opening an account? Is it safe to open a stock account by mobile phone?
每日一题:回文链表(剑指off027)
Binary tree experience
shell第三天小练习 通过自搭建dns服务器访问自搭建nextcloud网盘服务
5. < tag dynamic programming and complete knapsack problem> lt.70 Climb stairs | | advanced version + lt.322 Change + lt.139 Word split + lt.279 Complete square DBC
liunx中FileDescriptor与打开文件之间的关系
毕业四年换了3份软件测试工作,我为何依然焦虑?
大雪菜味题解--查找文献
Une seule ligne de texte dépasse l'ellipse partielle, plusieurs lignes de texte dépassent l'ellipse partielle, spécifiez plusieurs lignes
一组简单多用途表单小部件代码
Execution plan of SQL statement
Pytest interface automated testing framework | confitest Py and @pytest Fixture() combination
GDB debugging skills: positioning program stuck problem
Vs publish websites using webdeploy
單行文本 超出部分省略號,多行文本超出部分省略號,指定多行
OpenCV DFT




![[STL] simulation implementation vector](/img/c3/c0be38ed68d66ab08086dc43f5a036.png)




