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

哪个网站能上传自己做的简历新人跑业务怎么找客户

哪个网站能上传自己做的简历,新人跑业务怎么找客户,如何做赚钱的网站,淘宝客做销量的网站有哪些我们知道,在多线程中 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.shuangfujiaoyu.com/news/26065.html

相关文章:

  • 怎么利用招聘网站做薪酬调查seo公司推广宣传
  • 网站建设迅雷群排名优化软件
  • 沧州建设银行招聘网站盐城seo培训
  • 网页设计与网站开发的总结安装百度一下
  • 视频号怎么经营seo查询百科
  • 网站设计验收商城推广软文范文
  • 仿造网站用侵权吗在线建站网页制作网站建设平台
  • 创建全国文明城市建议简短优化网站
  • 架构图在什么网站可以做公司企业网站建设
  • 建站之星做出的网站不安全如何制作网站最简单的方法
  • 什么网站做任务赚钱吗万能搜索网站
  • jsp网站怎么做品牌运营总监
  • 常州h5网站建设无锡百度推广代理公司
  • 网站模板佳好乐云seo能打开任何网站浏览器
  • 毕业论文网站开发的参考文献nba最新交易汇总实时更新
  • 东莞seo技术培训西安seo优化
  • 两学一做知识竞答网站电商运营公司简介
  • 厦门有做网站建设温州网站建设优化
  • 广州网站建设团队搜索引擎优化seo多少钱
  • 怎么把做的网页放入网站seo干什么
  • wordpress 域名邮箱设置关键词优化推广排名多少钱
  • 做网站推广和头条推广网络营销和传统营销有什么区别
  • 网站如何做美工移动建站模板
  • 运营网站需要多少钱app营销推广方案
  • 黄山网站建设百度引擎
  • 台州做网站的公司品牌形象推广
  • 计算机网络技术电商网站建设与运营品牌建设的五个要素
  • 即墨网站建设公司百度竞价推广的技巧
  • 网站建设合同书下载百度无广告搜索引擎
  • 河南建设厅全能优化大师