JUC并发编程

作者:@冰山醉酒
本文为作者原创,转载请注明出处:https://www.cnblogs.com/douFrank/p/16117932.html


1|0什么是JUC

java.util 工具包,包,分类

业务:普通的线程代码:Thread

Runnable 没有返回值,效率相对Callable较低

2|0线程和进程

线程、进程,如果不能用一句话说出来的技术,不扎实!

进程:一个程序,QQ.exe、Music.exe程序的集合

一个进程往往可以包含多个线程,至少有一个

java默认有两个线程,main线程和GC进程

java真的能开启线程吗 开不了

1 public synchronized void start() { 2 /** 3 * This method is not invoked for the main method thread or "system" 4 * group threads created/set up by the VM. Any new functionality added 5 * to this method in the future may have to also be added to the VM. 6 * 7 * A zero status value corresponds to state "NEW". 8 */ 9 if (threadStatus != 0) 10 throw new IllegalThreadStateException(); 11 12 /* Notify the group that this thread is about to be started 13 * so that it can be added to the group's list of threads 14 * and the group's unstarted count can be decremented. */ 15 group.add(this); 16 17 boolean started = false; 18 try { 19 start0(); 20 started = true; 21 } finally { 22 try { 23 if (!started) { 24 group.threadStartFailed(this); 25 } 26 } catch (Throwable ignore) { 27 /* do nothing. If start0 threw a Throwable then 28 it will be passed up the call stack */ 29 } 30 } 31 } 32 //本地方法,底层的C++,Java无法直接操作硬件 33 private native void start0();

并发、并行

并发编程;并发,并行

并发(多个线程操作同一个资源)

  • CPU一核,模拟出来多条线程,天下武功,唯快不破,快速交替

并行(多个人一起行走)

  • CPU多核,多个线程可以同时执行;

package com.Study; import org.omg.SendingContext.RunTime; public class demo01 { public static void main(String[] args) { //获取CPU的核数 //CPU密集型,IO密集型 System.out.println(Runtime.getRuntime().availableProcessors()); } }

 

 


__EOF__

本文作者冰山醉酒
本文链接https://www.cnblogs.com/douFrank/p/16117932.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   冰山醉酒  阅读(47)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示