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();
        }
    }

  • 相关阅读:
    kill process
    USB development guide
    MMC device
    memtester
    printf()格式化输出详解
    C语言动态内存分配
    归并排序C语言
    c 文件操作
    数据包分析
    C语言文件操作函数大全
  • 原文地址:https://www.cnblogs.com/vonk/p/3894579.html
Copyright © 2011-2022 走看看