zoukankan      html  css  js  c++  java
  • 多线程

    答案:不能

    线程之间的关系,是“协同式”的,不是“抢占式”的。

    yield不会强制让渡CPU, interrupt也不会强制停止线程。

    根据源码注释:

    • 调用yield,只是想处理器processor暗示:“当前线程愿意让渡yield时间片”。但是处理器可以自由的忽略这个暗示。
    • 这就说明了:线程之间的关系,是“协同式”的,不是“抢占式”的
    • yield方法对于debugging或者testing的帮助很大,可以帮助减少由于竞争条件造成的bug
    /**
         * A hint to the scheduler that the current thread is willing to yield
         * its current use of a processor. The scheduler is free to ignore this
         * hint.
         *
         * <p> Yield is a heuristic attempt to improve relative progression
         * between threads that would otherwise over-utilise a CPU. Its use
         * should be combined with detailed profiling and benchmarking to
         * ensure that it actually has the desired effect.
         *
         * <p> It is rarely appropriate to use this method. It may be useful
         * for debugging or testing purposes, where it may help to reproduce
         * bugs due to race conditions. It may also be useful when designing
         * concurrency control constructs such as the ones in the
         * {@link java.util.concurrent.locks} package.
         */
        public static native void yield();
  • 相关阅读:
    审核系统
    ehcache 缓存
    tomcat 内存设置
    html5 开发 跨平台 桌面应用
    service thread 结合使用
    html5桌面应用
    鼠标 事件
    服务器 判断 客户端 文件下载
    使用github管理Eclipse分布式项目开发
    uub代码
  • 原文地址:https://www.cnblogs.com/frankcui/p/15402200.html
Copyright © 2011-2022 走看看