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

哪个网站能上传自己做的简历百度指数查询平台

哪个网站能上传自己做的简历,百度指数查询平台,网站到期后如何转域名,济南seo网站建设我们知道,在多线程中 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.bjxfkj.com.cn/article/104365.html

相关文章:

  • 做3dmax效果图任务的网站京东关键词优化技巧
  • 在网站写小说怎么做封面seo网络推广师招聘
  • 简述建立一个网站模板步骤软文自助发布平台系统
  • 建浏览器网站制作自制网页
  • 湖南建设网站百度小程序入口官网
  • 最好的优化公司网站推广优化外包便宜
  • 手机短视频制作自学教程上海全国关键词排名优化
  • 平台式建站网站运营工作的基本内容
  • 外贸网站空间哪个好艾滋病多长时间能查出来
  • pv3d 优秀网站中公教育培训机构官网
  • 有域名怎么建网站如何制作企业网站
  • 郑州做响应式网站seo搜索引擎优化主要做什么
  • 世界疫情最新消息今天排名表照片关键词优化公司电话
  • 山东广饶建设银行网站网站建站网站
  • 户外商品网站制作如何开发微信小程序
  • 企业做网站分哪几种百度seo排名查询
  • logo设计公司 北京seo线上培训机构
  • 莱芜都市网人才招聘seo外包公司优化
  • 网站必须做公安部备案长春网站公司哪家好
  • 建立网站赚钱seo系统培训哪家好
  • 网站建设基础流程摘要百度服务商
  • 游戏卡充值可以做网站吗拼多多推广引流软件免费
  • 推广策略研究河北网站seo外包
  • 黄埔网站建设 信科网络站内seo优化
  • 游戏app软件开发公司洛阳seo外包公司费用
  • 游戏ui设计师网站有哪些推广app是什么工作
  • 网站当地公安备案西安外包网络推广
  • 浦东新区建设局官方网站百度云盘网页版
  • 杭州关键词优化平台深圳网站seo哪家快
  • 商城微网站如何做防晒霜营销软文