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

广州网站建设信科便宜已经备案的网站新增ip怎么做

广州网站建设信科便宜,已经备案的网站新增ip怎么做,惠来网站建设,怎样建立企业网站我们知道#xff0c;在多线程中 Thread thread new Thread(runnable); thread.start();以及 thread.run();都可以执行runnable中run方法下的代码#xff0c;但是二者又有所不同 下面给出一段代码用以体现二者的区别#xff1a; 以下代码中#xff0c;通过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 groups list of threads* and the groups 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.dnsts.com.cn/news/190739.html

相关文章:

  • 泌阳县网站建设中原城市领先指数
  • 从化做网站建设免费网站软件app大全
  • 太原网站建设与维护网站模版 蓝色
  • 公司主营业务网站建设吴江网页制作
  • 深圳商城网站设计电话软件开发工程师英文
  • 给公司做企业网站建设门户网站培训通知
  • 网站建设350元做网站一般多少钱
  • 做药的常用网站有哪些论坛网站免费建设模板下载安装
  • 公司网站改版方案盛世平面设计网站中文
  • 美工素材网站有哪些有域名了网站怎么做
  • 地理云门户网站建设庆阳官网贴吧
  • 青岛做网站建设的公司排名企业营销策划书
  • 张店低价网站建设湖北广盛建设集团网站
  • c 网站开发框架做商城型网站
  • 商务网站开发实验电商平台代运营
  • 新手做网站看什么书4a网站建设公司
  • 平台型网站建设方案wordpress外网访问没模版
  • 百度收录最快的网站泰安集团网站建设地点
  • 青海市住房和城乡建设厅网站2018年主流网站开发语言
  • 网站正在建设中色免费开网店怎么开
  • 公众号开发者葫岛百度seo
  • 青岛网站推广招商是普通网站地图好还是rss地图好一点
  • 青锐成长计划网站开发人员杭州企业自助建站系统
  • 华为等五家公司南昌关键词优化平台
  • 茌平建设局网站开发一个小程序一般需要多少钱呢
  • 宣威市网站建设站酷网免费素材图库官网
  • 呼和浩特装修网站织梦网站怎么把index.html去掉
  • 娱乐网站 建站软件怎样制作网站
  • 百度网站收入天津 网站设计公司
  • 小型项目外包网站中国建筑网官网证书查询