線性求 $i^i$ 的做法
阿新 • • 發佈:2022-04-05
什麼是JUC
java.util 工具包,包,分類
Runnable 沒有返回值,效率相對Callable較低
執行緒和程序
執行緒、程序,如果不能用一句話說出來的技術,不紮實!
程序:一個程式,QQ.exe、Music.exe程式的集合
一個程序往往可以包含多個執行緒,至少有一個
java預設有兩個執行緒,main執行緒和GC程序
java真的能開啟執行緒嗎 開不了
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 then
it will be passed up the call stack */
}
}
}
//本地方法,底層的C++,Java無法直接操作硬體
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());
}
}