JUC并发编程
什么是JUC
java.util 工具包,包,分类
Runnable 没有返回值,效率相对Callable较低
线程和进程
线程、进程,如果不能用一句话说出来的技术,不扎实!
进程:一个程序,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()); } }

浙公网安备 33010602011771号