`

Java Thread programming basical knowledge

阅读更多

yield() :
Give a hint to the thread scheduling mechanism that, you’ve done enough and some other thread might as well have the CPU. And this is really a hint --- there is no guarantee that your implementation will listen to you! And this hint takes the form of the yield() method.
In general, yield( ) is useful only in rare situations, and you can’t rely on it to do any serious tuning of your application.

join():
a.join();  a will run first, the thread who call a.join(); will block, until a finished running.
Code example: for(int i = 0; I < 5; i++) newSleepingThread().join();

The difference between yield() and sleep()
yield() means release the CPU immediately, I just give up the use of CPU, I give somebody else to use CPU. But I didn’t go to sleep.
sleep(ms) means I will go to sleep for ms million seconds. I may waked up by somebody else(if somebody call myThread.interrupt();), so this is an exception! Need to be surrounded by try catch. wait() is quite similar in this scenario.

Just remember: don’t control the execution order using sleep() or yield(), there is no way to control using sleep() and yield() methods.

Daemon threads:
A daemon thread is one that is supposed to provide a general service in the background. It’s not part of the main application. So, when all the non-daemon threads complete, the program is terminated.


 

分享到:
评论

相关推荐

    Visual Basical教程

    第一章Visual Basic 6.0程序设计概述 第二章面向对象编程基础 第三章VB语法基础 第四章基本程序结构 第五章数组 第六章子程序和函数 第七章程序调试和错误处理 第八章窗体(Form)和简单的输入输出 ...

    computer vision basical dilation & erosion

    计算机视觉是信息技术领域的一个重要分支,它涉及到图像处理、机器学习和模式识别等多个学科的交叉。在计算机视觉中,图像的形态学操作如膨胀(Dilation)和腐蚀(Erosion)是基本且非常有用的工具,尤其在图像分割...

    netsign-basic.jar

    数字签名基础jar

    matlab转换java代码-Vehicle-Detection:车辆检测

    matlab转换java代码车辆检测 用于视频帧中车辆检测的OpenCV Python程序 人脸检测基础 所给出程序的目的是检测视频帧中的感兴趣对象(汽车)并保持跟踪同一对象。 这是一个如何在Python中检测车辆的示例。...basical

    DNS.rar_dns

    Basical Concept for DNS

    Visual Basic读取EXCEL文件含完整源代码

    在IT行业中,编程语言Visual Basic(VB)是一个广泛使用的工具,尤其在开发Windows应用程序时。在给定的压缩包文件中,"Visual Basic读取EXCEL文件含完整源代码"是一个示例项目,展示了如何利用VB来操作Excel文件,...

    lte rf optimization pricinpial

    the basical guideline of rf network performance optimization

    aco.rar_ACO_ant_ant algorithm_ant colony algorithm_searching met

    A new heuristic algorithm-ant colony optimization and its basical theory are introduced in this article to solve the complicated and optimized questions.This method simulates the course of ant ...

    Algorithm-betterdocs.zip

    Algorithm-betterdocs.zip,Web版的https://github.com/khusnetdinov/ruby.basical repo-带有Ruby示例和参考的基础编程。它涵盖了线程、实体原理、设计模式、数据结构、算法。供阅读的书。,算法是为计算机程序高效、...

    PHP人民币金额转大写实例代码

    `$basical`数组包含数字0到9对应的中文数字,而`$advanced`数组包含拾、佰、仟等位值单位。这些数组用于在转换过程中查找和组合相应的中文数字和单位。 转换逻辑中的一个关键点是对“零”的处理。在人民币金额中,...

    vb宿舍管理系统论文

    是用vb做前台,sql做后台的宿舍管理系统论文

Global site tag (gtag.js) - Google Analytics