JUC并发编程学习笔记

JUC(并发编程),java.util.concurrent得工具类 image.png 首先得了解进程和线程得关系和区别: 进程:进程是一个具有一定独立功能的程序关于某个数据集合的一次运行活动。它是操作系统动态执行的基本单元,在传统的操作系统中,进程既是基本的分配单元,也是基本的执行单元。

线程:通常在一个进程中可以包含若干个线程,当然一个进程中至少有一个线程,不然没有存在的意义。线程可以利用进程所拥有的资源,在引入线程的操作系统中,通常都是把进程作为分配资源的基本单位,而把线程作为独立运行和独立调度的基本单位,由于线程比进程更小,基本上不拥有系统资源,故对它的调度所付出的开销就会小得多,能更高效的提高系统多个程序间并发执行的程度。 例子:idea开发工具开启时是一整个进程,分别有代码检测的线程和自动保存代码的线程. 使用QQ,查看进程一定有一个QQ.exe的进程,我可以用qq和A文字聊天,和B视频聊天,给C传文件,给D发一段语言,QQ支持录入信息的搜索。 线程得五种状态:直接看源码(Thread.State)

1Thread.State 2 3 4public enum State { 5 /** 6 * Thread state for a thread which has not yet started. 7 */ 8 NEW,(新建) 9 10 /** 11 * Thread state for a runnable thread. A thread in the runnable 12 * state is executing in the Java virtual machine but it may 13 * be waiting for other resources from the operating system 14 * such as processor. 15 */ 16 RUNNABLE,(准备就绪) 17 18 /** 19 * Thread state for a thread blocked waiting for a monitor lock. 20 * A thread in the blocked state is waiting for a monitor lock 21 * to enter a synchronized block/method or 22 * reenter a synchronized block/method after calling 23 * {@link Object#wait() Object.wait}. 24 */ 25 BLOCKED,(阻塞) 26 27 /** 28 * Thread state for a waiting thread. 29 * A thread is in the waiting state due to calling one of the 30 * following methods: 31 * <ul> 32 * <li>{@link Object#wait() Object.wait} with no timeout</li> 33 * <li>{@link #join() Thread.join} with no timeout</li> 34 * <li>{@link LockSupport#park() LockSupport.park}</li> 35 * </ul> 36 * 37 * <p>A thread in the waiting state is waiting for another thread to 38 * perform a particular action. 39 * 40 * For example, a thread that has called <tt>Object.wait()</tt> 41 * on an object is waiting for another thread to call 42 * <tt>Object.notify()</tt> or <tt>Object.notifyAll()</tt> on 43 * that object. A thread that has called <tt>Thread.join()</tt> 44 * is waiting for a specified thread to terminate. 45 */ 46 WAITING,(不见不散) 47 48 /** 49 * Thread state for a waiting thread with a specified waiting time. 50 * A thread is in the timed waiting state due to calling one of 51 * the following methods with a specified positive waiting time: 52 * <ul> 53 * <li>{@link #sleep Thread.sleep}</li> 54 * <li>{@link Object#wait(long) Object.wait} with timeout</li> 55 * <li>{@link #join(long) Thread.join} with timeout</li> 56 * <li>{@link LockSupport#parkNanos LockSupport.parkNanos}</li> 57 * <li>{@link LockSupport#parkUntil LockSupport.parkUntil}</li> 58 * </ul> 59 */ 60 TIMED_WAITING,(过时不候) 61 62 /** 63 * Thread state for a terminated thread. 64 * The thread has completed execution. 65 */ 66 TERMINATED;(终结) 67}

线程中睡眠时Wait/Sleep两种用法得区别 功能都是当前线程暂停. wait放开手去睡,放开手里的锁 sleep握紧手去睡,醒了手里还有锁 有并发就有并行两者区别 并发:同一时刻多个线程在访问同一个资源,多个线程对一个点 例子:小米9今天上午10点,限量抢购 春运抢票 电商秒杀... 并行:多项工作一起执行,之后再汇总 例子:泡方便面,电水壶烧水,一边撕调料倒入桶中

注:以上是学习过程所做笔记,有不足请指出.

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )