JAVA concurrent programming notes (a)

First, the concept understanding

(1) What is the parallel, concurrent?

并行:即通过多个CPU,让多个线程共同运行
并发:微观上来看,并不是多个线程共同运行,而是每个线程允许占用的CPU时间非常短(用户感觉不出),让多个线程轮流使用CPU。

(2) What is the throughput?

吞吐量是指对网络、设备、端口、虚电路或其他设施,单位时间内成功地传送数据的数量。

Second, the thread implementation methods

(1) Tread class inheritance, overriding the run method

public class ThreadA extends Thread{
public void run(){
super.run();

}
}

(2) to achieve Runnable interface, run method

public class ThreadB implements Runnable{
public void run(){

}
}

(3) implement Callable interface, call method

public class implements Callable{
public String call() throw Exception{

}
}

Third, the thread interrupt mechanism

(1) calls Thread.stop (), insecure, not recommended

(2) the use of Thread.interrupt (), needs to be interrupted thread to make their own treatment

Published 24 original articles · won praise 0 · Views 612

Guess you like

Origin blog.csdn.net/weixin_43896829/article/details/103154273