zoukankan      html  css  js  c++  java
  • 线程的礼让

    在线程操作中,可以使用yield()方法将一个线程的操作暂时让给其他线程执行:

    class MyThread17 implements Runnable {
        public void run() {
            for (int i = 0; i < 5; i++) {
                System.out.println(Thread.currentThread().getName() + " run---->"
                        + i);
                if (i == 3) {
                    System.out.println("Thread yield:");
                    Thread.currentThread().yield();
                }
            }
        }
    }

    public class ThreadYieldDemo {
        public static void main(String[] args) {
            MyThread17 my = new MyThread17();
            Thread t1 = new Thread(my, "THread A");
            Thread t2 = new Thread(my, "THread B");
            t1.start();
            t2.start();
        }
    }

  • 相关阅读:
    P1338 末日的传说
    P1364医院设置
    线程
    进程通信
    CentOS设置中文
    C++快读讲解
    迭代加深搜索
    P1118 [USACO06FEB]Backward Digit Sums G/S
    N皇后问题
    RMQ区间最值查询
  • 原文地址:https://www.cnblogs.com/vonk/p/3894579.html
Copyright © 2011-2022 走看看