1. Thread.yield():

api中解释: 暂停当前正在执行的线程对象,并执行其他线程。

注意:这里的其他也包含当前线程,所以会出现以下结果。

  1. public class Test extends Thread {
  2. public static void main(String[] args) {
  3. for (int i = 1; i <= 2; i++) {
  4. new Test().start();
  5. }
  6. }
  7. public void run() {
  8. System.out.print("1");
  9. yield();
  10. System.out.print("2");
  11. }
  12. }

输出结果: 1122 或者 1212

2. Thread.sleep(long millis):

解释:使当前线程暂停millis所指定的毫秒,转到执行其它线程。

Thread.sleep() 和 Thread.yield() 区别的更多相关文章

  1. PHP版本VC6和VC9、Non Thread Safe和Thread Safe的区别

    链接:http://www.cnblogs.com/neve/articles/1863853.html 想更新个PHP的版本,PHP的windows版本已经分离出来了,见http://windows ...

  2. 操作系统基础知识之————单线程(Thread)与多线程的区别

    单线程(Thread)与多线程的区别 (一)首先了解一下cpu: 随着主频(cpu内核工作时钟频率,表示在CPU内数字脉冲信号震荡的速度,等于外频(系统基本时间)乘倍频)的不断攀升,X86构架的硬件逐 ...

  3. Thread.currentThread()和this的区别——《Java多线程编程核心技术》

    前言:在阅读<Java多线程编程核心技术>过程中,对书中程序代码Thread.currentThread()与this的区别有点混淆,这里记录下来,加深印象与理解. 具体代码如下: pub ...

  4. java中的线程问题(三)——继承Thread VS 实现Runnable的区别

    从java的设计来看,通过继承Thread或者实现Runnable接口来创建线程本质上没有区别,从jdk帮助文档我们可以看到Thread类本身就实现了Runnable接口,如果一定要说它们有什么区别, ...

  5. Thread.currentThread()与this的区别

    Thread.currentThread()与this的区别: Thread.currentThread()方法返回的是对当前正在执行的线程对象的引用,this代表的是当前调用它所在函数所属的对象的引 ...

  6. Java 使用new Thread和线程池的区别

    本文转至:https://www.cnblogs.com/cnmenglang/p/6273761.html , 孟凡柱的专栏 的博客,在此谢谢博主! 1.new Thread的弊端执行一个异步任务你 ...

  7. 源码查看Thread.interrupted()和Thread.currentThread().isInterrupted()区别

    JAVA线程状态.线程START方法源码.多线程.JAVA线程池.如何停止一个线程等多线程问题 这两个方法有点容易记混,这里就记录一下源码. Thread.interrupted()和Thread.c ...

  8. Thread.sleep()和Thread.currentThread().sleep()区别

    先看一下代码 public class Thread1 extends Thread{ @Override public void run() { try { System.out.println(& ...

  9. Thread.sleep( ) vs Thread.yield( )

    Thread.sleep() The current thread changes state from Running to Waiting/Blocked as shown in the diag ...

  10. C#异步和多线程以及Thread、ThreadPool、Task区别和使用方法

    本文的目的是为了让大家了解什么是异步?什么是多线程?如何实现多线程?对于当前C#当中三种实现多线程的方法如何实现和使用?什么情景下选用哪一技术更好? 第一部分主要介绍在C#中异步(async/awai ...

随机推荐

  1. GIT-查看config配置信息

    config 配置指令 1 git config config 配置有system级别 global(用户级别) 和local(当前仓库)三个 设置先从system->global->lo ...

  2. jeecg中的树形控件demo

    1.comboTree控件 1.页面方法: <t:comboTree url="jeecgFormDemoController.do?getComboTreeData" va ...

  3. storyboard貌似不错

    冷静下来看了下,貌似聽简单,蛋疼,忙完才发现,弄的时候咋没发现,靠 push,present等可以全部用下面这个api搞定 - (void)performSegueWithIdentifier:(NS ...

  4. WindowsServer2012显示计算机的方法

    WindowsServer2012显示计算机的方法 (转) 消失的"计算机"?[这周九叔工作比较忙,还有其他琐事缠身,因此SystemCenter2012SP1系列的发布稍慢,抱歉 ...

  5. (转)如何实现CSS限制字数,超出部份显示点点点...

    <div style="width:200px; white-space:nowrap;overflow:hidden;text-overflow:ellipsis; border:1 ...

  6. [转]iis 重新安装后 重新注册asp.net

    iis 重新安装后 重新注册asp.net 服务器IIS问题: 卸载并重新安装了IIS.... 解决方法:原因是IIS重装后要重新安装一下.NET Framework. 开始-->运行--> ...

  7. [ML] Gradient Descend Algorithm [Octave code]

    function [theta, J_history] = gradientDescentMulti(X, y, theta, alpha, num_iters) m = length(y); % n ...

  8. Nginx 是前端工程师的好帮手

    Nginx [engine x] 是俄罗斯的 Igor Sysoev 编写的一个 强大的 HTTP 和反向代理服务器,而且也推出了 Windows 版本.Windows 版本使用 select 模型, ...

  9. CImage 往Picture Control贴图 图像显示不正常

    在使用CImage 往vc控件 picture Control 上贴图的时候图像显示不太正常如图: 已知原始图片的宽高为640*640  而我上面picture Control  控件宽高小于原始图像 ...

  10. 1 数据库开发--MySQL介绍

    1.数据库管理软件 C/S 并发.锁 :SQL语句.语法 基本管理和语法学习 一.介绍: mysql数据库管理软件: 套接字:服务端,客户端:客户端可访问服务端得数据 1.支持并发:操作得是共享得数据 ...