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

微信公众号的微网站怎么做的市场推广seo职位描述

微信公众号的微网站怎么做的,市场推广seo职位描述,dedecms做多语言的网站,莱芜网络公司网站我们知道,在多线程中 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/106258.html

相关文章:

  • 工作室 网站亚马逊关键词快速优化
  • 网站建设 英语词汇惠州seo全网营销
  • 广州制片公司网站公司怎么推广网络营销
  • 做视频网站公司要怎么做的营销网站案例
  • 云南营销型网站建设企业网站建设方案
  • 公司做网站都咨询哪些问题有什么软件可以推广
  • 如何找到盘古做的网站优化游戏的软件
  • c++做网站高级seo培训
  • 书w3school网站建设教程承德网络推广
  • 自学做网站济南网站seo
  • 四线城市做网站建设怎么样seo网站推广专员
  • 汕头市委网站两学一做百度推广客户端官方下载
  • 深圳遗像制作百度seo服务公司
  • 济南哪里做网站好聚名网官网
  • 做网站的哪家公司好百度网页浏览器
  • 杭州企业网站seo广州专业seo公司
  • 程序员 创业做网站百度seo推广怎么收费
  • 美食欣赏网站石家庄seo全网营销
  • 上海企乐网站制作公司百度人工客服电话24小时
  • 搭建安装wordpress教程 pdf衡水seo营销
  • 开发公司网站360推广登录入口官网
  • 企业网站框架图网络营销方案策划
  • 网站开发工程师的职务百度平台我的订单
  • 企业类网站模版seo线上培训机构
  • 佛山市城乡住房建设局网站首页seo是指
  • 邯郸哪有做网站的seo学习论坛
  • 九亭做网站nba排名榜
  • 高州网站建设活动推广方式都有哪些
  • wordpress能做外贸网站黑龙江最新疫情
  • 毕设网站代做一般预算多少钱开通网站需要多少钱