当前位置: 首页 > news >正文

哪个网站能上传自己做的简历下载百度语音导航地图安装

哪个网站能上传自己做的简历,下载百度语音导航地图安装,门户型网站建设,小米商城wordpress我们知道,在多线程中 Thread thread new Thread(runnable); thread.start();以及 thread.run();都可以执行runnable中run方法下的代码,但是二者又有所不同 下面给出一段代码用以体现二者的区别: 以下代码中,通过thread.start()启…

我们知道,在多线程中
Thread thread = new Thread(runnable);
thread.start();以及 thread.run();都可以执行runnable中run方法下的代码,但是二者又有所不同
下面给出一段代码用以体现二者的区别:
以下代码中,通过thread.start()启动线程,最终产生了线程阻塞

package com.xuecheng;/*** @author Zonda* @version 1.0* @description TODO* @2024/6/15 16:23*/
public class ThreadLocal {public static void main(String[] args) {Runnable runnable = new Runnable() {@Overridepublic void run() {synchronized (this){while(true){try {Thread.sleep(1000);} catch (InterruptedException e) {throw new RuntimeException(e);}System.out.println("打了一发");}}}};Thread thread = new Thread(runnable);thread.start();Thread thread2 = new Thread(runnable);thread2.start();}
}

但如果是调用run方法区启动就不会,这是为什么呢?

        Thread thread = new Thread(runnable);thread.run();Thread thread2 = new Thread(runnable);thread2.run();

因为当我们直接调用run方法执行的时候,这是直接在main方法的主线程中调用run方法,并没有开启一个新的线程,因此 thread.run();和 thread2.run();会在main方法的主线程中顺序执行。这样就不会出现两个线程去争抢同一个锁中的资源的情况。
在这里插入图片描述
而执行start方法会在main线程中异步地开启一个新线程去执行run方法中的代码,如果有两个线程执行start方法,就会出现两个线程同时去执行run方法中的情况。如果一个其中一个线程休眠的时候另一个线程访问这个方法还好,可以交替访问;但是一旦出现一个线程在执行run方法的时候,另一个线程也同时要执行run方法,但是synchronized关键字中的元素只能被一个线程访问,最终会卡死。
在这里插入图片描述
我们通过阅读源码也可以看出只有在调用start方法的时候才会创建线程:
start0();

    public synchronized void start() {/*** This method is not invoked for the main method thread or "system"* group threads created/set up by the VM. Any new functionality added* to this method in the future may have to also be added to the VM.** A zero status value corresponds to state "NEW".*/if (threadStatus != 0)throw new IllegalThreadStateException();/* Notify the group that this thread is about to be started* so that it can be added to the group's list of threads* and the group's unstarted count can be decremented. */group.add(this);
// 将当前线程对象添加到它的线程组。线程组是一种管理线程的机制,可以对线程进行分组管理。boolean started = false;try {start0();started = true;//start0();执行成功,走到这里说明线程创建成功} finally {try {if (!started) {group.threadStartFailed(this);}} catch (Throwable ignore) {/* do nothing. If start0 threw a Throwable thenit will be passed up the call stack */}}}private native void start0();
http://www.yidumall.com/news/79256.html

相关文章:

  • 苏州吴中区建设局网站上海seo公司
  • 做班级玩网站做哪些方面线下推广怎么做
  • wordpress网站流量厦门头条今日新闻
  • 博物馆网站建设依据免费域名申请
  • 杭州的电商网站建设天津关键词优化专家
  • 网站建设精美模板下载百度推广渠道
  • 福州仿站定制模板建站百度网盘下载安装
  • jsp mysql开发网站开发如何建立电商平台
  • 恶搞图片制作器一点优化
  • 设计网站公司有哪些搜索引擎营销的主要方法
  • 制作一个app软件东营seo网站推广
  • 如何免费建造网站长沙正规seo优化公司
  • 南昌地宝网最新招聘信息杭州seo整站优化
  • 网站可以做系统吗十大接单平台
  • 佛山企业如何建网站如何百度推广
  • 资源付费网站制作合肥百度关键词优化
  • 网页在线制作网站怎么优化网站排名才能起来
  • wordpress百度seo插件百度优化是什么意思
  • 什么是网站建设整体策划方案海外网络推广平台
  • 沈阳直销网站制作公司湖南seo推广软件
  • 公司建个网站要多少钱网站设计报价方案
  • 网页制作的公司收费推广seo网站
  • 山东省建设厅执业资格注册中心网站比百度好用的搜索引擎
  • WordPress商务网站石家庄网站seo
  • 个人网站建设分几个步走网站技术制作
  • 凡高网站建设外包公司的优势和劣势
  • 包头网站建设兼职自媒体营销的策略和方法
  • 织梦系统做的商城网站seo网站优化做什么
  • dede网站地图路径修改怎么做网站模板
  • 开锁都在什么网站做企业网站推广建议