package com.Bubbles.Demo4.线程礼让;
//测试礼让线程
//礼让不一定成功,cpu心情
public class testyied {
public static void main(String[] args) {
Myyied Myyied = new Myyied ();
new Thread (Myyied,"a").start ();
new Thread (Myyied,"b").start ();
}
}
class Myyied implements Runnable{
@Override
public void run() {
System.out.println (Thread.currentThread ().getName ()+"线程开始执行");
Thread.yield ();//线程礼让
System.out.println (Thread.currentThread ().getName ()+"线程停止执行");
}
}
多线程线程礼让
最新推荐文章于 2024-06-19 21:11:55 发布