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

建设官方网站铁岭网站seo

建设官方网站,铁岭网站seo,专门帮忙做网站的公司,莆田企业制作网站什么是JUC JUC指的是:Java里的三个包 java.util.concurrentjava.util.concurrent.atomic:原子性java.util.concurrent.locks:lock锁回顾线程和进程 进程 程序执行的一次过程,一个进程包含一个或多个线程。进程是资源分配的单位 …

什么是JUC

    JUC指的是:Java里的三个包

  • java.util.concurrent
  • java.util.concurrent.atomic:原子性
  • java.util.concurrent.locks:lock锁

 

回顾线程和进程

进程

        程序执行的一次过程,一个进程包含一个或多个线程。进程是资源分配的单位

线程

        可以指程序执行过程中,负责实现某个功能的单位。线程是CPU调度和执行的单位

并发

        同一时刻,多个线程交替执行。(一个CPU交替执行线程)

并行

        同一时刻,多个线程同时执行。(多个CPU同时执行多个线程)

    查询cpu核数

public class Test1 {public static void main(String[] args) {//查询cpu核数//CPU 密集型,IO密集型System.out.println(Runtime.getRuntime().availableProcessors());}
}

并发编程的本质

        并发编程的本质是充分利用cpu资源。

    问题:Java真的可以开启线程吗

        不可以。Java创建Thread类调用start方法,底层是把线程放到一个组里面,然后调用一个本地方法start0;方法底层是C++;Java无法操作硬件

Thread部分源码

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;} 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 */}}}//本地方法,底层的C++ java无法直接操作硬件private native void start0();

多线程回顾

线程的几种状态

        新生状态、运行状态、阻塞状态、等待状态(死等)、超时等待状态(过期不候)、停止状态

    Thread.State的源码

public enum State {/*** Thread state for a thread which has not yet started.*/// 新生NEW,/*** Thread state for a runnable thread.  A thread in the runnable* state is executing in the Java virtual machine but it may* be waiting for other resources from the operating system* such as processor.*/// 运行RUNNABLE,/*** Thread state for a thread blocked waiting for a monitor lock.* A thread in the blocked state is waiting for a monitor lock* to enter a synchronized block/method or* reenter a synchronized block/method after calling* {@link Object#wait() Object.wait}.*/// 阻塞BLOCKED,/*** Thread state for a waiting thread.* A thread is in the waiting state due to calling one of the* following methods:* <ul>*   <li>{@link Object#wait() Object.wait} with no timeout</li>*   <li>{@link #join() Thread.join} with no timeout</li>*   <li>{@link LockSupport#park() LockSupport.park}</li>* </ul>** <p>A thread in the waiting state is waiting for another thread to* perform a particular action.** For example, a thread that has called <tt>Object.wait()</tt>* on an object is waiting for another thread to call* <tt>Object.notify()</tt> or <tt>Object.notifyAll()</tt> on* that object. A thread that has called <tt>Thread.join()</tt>* is waiting for a specified thread to terminate.*/// 等待,死死的等待WAITING,/*** Thread state for a waiting thread with a specified waiting time.* A thread is in the timed waiting state due to calling one of* the following methods with a specified positive waiting time:* <ul>*   <li>{@link #sleep Thread.sleep}</li>*   <li>{@link Object#wait(long) Object.wait} with timeout</li>*   <li>{@link #join(long) Thread.join} with timeout</li>*   <li>{@link LockSupport#parkNanos LockSupport.parkNanos}</li>*   <li>{@link LockSupport#parkUntil LockSupport.parkUntil}</li>* </ul>*/// 超时等待TIMED_WAITING,/*** Thread state for a terminated thread.* The thread has completed execution.*/// 终止TERMINATED;}

sleep和wait的区别

  1. sleep是Thread类的本地方法;wait是Object类的方法。
  2. sleep不释放锁;wait释放锁。
  3. sleep可以使用在任何地方;wait必须在同步代码块中
  4. sleep不需要和synchronized关键字一起使用;wait必须和synchronized代码块一起使用。
  5. sleep不需要被唤醒(时间到了自动退出阻塞);wait需要被唤醒。
  6. sleep一般用于当前线程休眠,或者轮循暂停操作;wait则多用于多线程之间的通信。
  7. sleep和wait都需要捕获异常

http://www.dtcms.com/wzjs/402145.html

相关文章:

  • 山东天元建设集团破产重庆seo推广运营
  • 可以给别人做ps设计的网站网站建设是干嘛的
  • 做代码的网站app推广注册从哪里接单
  • 中山做网站联系电话广州网站建设推荐
  • 做外贸网站百度站长链接提交
  • 大朗镇仿做网站南京网站设计公司
  • 网络营销就是网络推广对吗优化推荐
  • 可以做动画的网站都有哪些软件网站模板大全
  • b2c电子商务网站.鄂州网站seo
  • 企业网站做的公司sem
  • 做自己的网站好还是博客好百度云app下载安装
  • 网站功能需求文档时事新闻热点摘抄
  • 温州网站推广效果好商品推广
  • 做58同城那样的网站搜狗站长平台
  • 网站怎么添加关键词国产长尾关键词拘挖掘
  • 从零开始学习网站开发国内最新新闻热点事件
  • 小企业网站建设建议360搜索首页
  • discuz绿色带门户手机网站模板临沂做网站的公司
  • 嘉定区整站seo十大排名广州婚恋网站排名
  • 网站动态海报效果怎么做的百度客户端在哪里打开
  • 做包装的网站有哪些营销推广费用方案
  • 溧水114网站开发常用的营销策略
  • 网站地图怎么建设云南seo网站关键词优化软件
  • 聊城做网站的公司行情关键词难易度分析
  • 如何用家庭电脑做网站2345网址导航官网
  • 乐清疫情最新消息今天新增本溪seo优化
  • 做招聘网站赚钱吗网站指数查询
  • 网站建设需要注意哪些事项网上哪里接app推广单
  • 网站设计公司-信科网络长沙seo网络营销推广
  • 网站分几个阶段建设贵州萝岗seo整站优化