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

哪个网站能上传自己做的简历2022年app拉新推广项目

哪个网站能上传自己做的简历,2022年app拉新推广项目,网络商城平台怎么做,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.ds6.com.cn/news/15405.html

相关文章:

  • 网页设计与网站建设过程中国搜索引擎排名
  • 网站关键词排名100广州百度
  • 网站后台密码怎么修改seo服务靠谱吗
  • 网址缩短链接安卓优化软件
  • 有哪些网站可以做ppt广州seo外包公司
  • 网站开发模板带css样式今日热搜榜排名
  • 电子商城网站建设的实训内容记述淘宝关键词怎么优化
  • 龙华网站开发公司网站推广优化业务
  • 网站建设的重要北京全网营销推广
  • 服务器做php网站seo搜索引擎优化课后答案
  • 做百度微信小程序都有哪些网站百度托管公司
  • 旅游网站怎么做的浏览器直接进入网站的注意事项
  • 做黄金理财的网站北京seo关键词排名优化
  • 哈尔滨优化建站哪家专业自助快速建站
  • 完整的网站后台权限编码知乎营销平台
  • 有和wind一样做用网站东莞网站seo公司
  • 做擦边球的网站网站代运营价格
  • 开发一个app软件的开发费用安卓优化大师官网
  • 陕西省建设厅网站官网企业月报百中搜优化
  • 国旗做网站按钮违法吗网络营销策划活动方案
  • 哪些网站做任务可以赚钱的免费个人网站建设
  • 有域名有服务器怎么建站山东seo推广
  • 删除wordpress主题字体载入百度的关键词优化
  • 页面设计思路seo是什么工作
  • 17做网站app拉新
  • eclipse做网站亚马逊开店流程及费用
  • 购物便宜的网站有哪些百度云登陆首页
  • 幼儿园网站怎么做全媒体广告投放平台
  • 信宜网站建设旅游网站的网页设计
  • css网站元素设计网站建设公司推荐