第10章 內(nèi)部類
- 創(chuàng)建內(nèi)部類
- 鏈接到外部類
- 使用.this和.new
- 內(nèi)部類與向上轉(zhuǎn)型
- 在方法和作用域內(nèi)的內(nèi)部類
- 匿名內(nèi)
6.1 再訪工廠方法 - 嵌套類
7.1 接口內(nèi)部的類
7.2 從多層嵌套類中訪問外部類的成員 - 為什么需要內(nèi)部類
8.1 閉包與回調(diào)
8.2 內(nèi)部類與控制框架 - 內(nèi)部類的繼承
- 內(nèi)部類可以被覆蓋嗎
- 局部?jī)?nèi)部類
- 內(nèi)部類標(biāo)識(shí)符
第15章 泛型
- 與C++的比較
- 簡(jiǎn)單泛型
2.1 一個(gè)元組類庫
2.2 一個(gè)堆棧類
2.3 RandomList - 泛型接口
- 泛型方法
4.1 杠桿利用類型參數(shù)推斷
4.2 可變參數(shù)與泛型方法
4.3 用于Generator的泛型方法
4.4 一個(gè)通用的Generator
4.5 簡(jiǎn)化元組的使用
4.6 一個(gè)Set實(shí)用工具 - 匿名內(nèi)部類
- 構(gòu)建復(fù)雜模型
- 擦除的神秘之處
- 擦除的補(bǔ)償
- 邊界
- 通配符
泛型類,泛型方法的使用實(shí)例
https://www.cnblogs.com/jpfss/p/9928747.html邊界通配符:extends和super
https://blog.csdn.net/qq_36898043/article/details/79655309
第21章 并發(fā)
并發(fā)的多面性
1.1 更快地執(zhí)行
1.2 改進(jìn)代碼設(shè)計(jì)基本的線程機(jī)制
2.1 定義任務(wù)
Runnable接口:https://blog.csdn.net/yangyechi/article/details/88079983
2.2 Thread類
Thread類構(gòu)造器接收Runnable對(duì)象;
繼承Thread類并覆蓋run方法;
2.3 使用Executor
Executor用于管理Thread對(duì)象;
CachedThreadPool,F(xiàn)ixedThreadPool,SingleThreadPool
線程池介紹:https://www.cnblogs.com/liyus/p/10235942.html
public static void main(String[] args) {
// 不建議這樣使用, 建議 new ThreadPoolExcutor(), 強(qiáng)制程序員理解其中各個(gè)參數(shù)的意思
ExecutorService executorService = Executors.newCachedThreadPool();
for(int i=0; i<5; i++){
executorService.execute(new TaskThread()); // thread對(duì)象或者runnable對(duì)象
}
executorService.shutdown(); // 不在接收任務(wù)
}
2.4 從任務(wù)中產(chǎn)生返回值
Callalbe接口+Future對(duì)象:https://blog.csdn.net/zsj777/article/details/85089993
2.5 休眠
2.6 優(yōu)先級(jí)
線程優(yōu)先級(jí):https://blog.csdn.net/weixin_37139197/article/details/81989749
2.7 讓步
yield:https://www.cnblogs.com/chinaifae/articles/10373846.html
2.8 后臺(tái)線程
https://blog.csdn.net/staticFinal_shuaibi/article/details/84865688
2.9 編碼的變體
2.10 術(shù)語
2.11 加入一個(gè)線程
join:https://www.iteye.com/blog/uule-1101994
2.12 創(chuàng)建有響應(yīng)的用戶界面
2.13 線程組
2.14 捕獲異常
共享受限資源
3.1 不正確地訪問資源
3.2 解決共享資源競(jìng)爭(zhēng)
Synchronized關(guān)鍵字的用法:https://www.cnblogs.com/fnlingnzb-learner/p/10335662.html
Synchronized關(guān)鍵字配合wait(), notify(), notifyAll()的使用:https://www.cnblogs.com/moongeek/p/7631447.html
Lock和Condition使用:https://www.cnblogs.com/renjianpiaoliu/p/9250444.html
Lock的實(shí)現(xiàn)原理:https://blog.csdn.net/w_s_h_y/article/details/77450166
復(fù)習(xí)Java內(nèi)存模型:https://www.cnblogs.com/songpingyi/p/9121745.html
3.3 原子性與易變性
原子性與易變性介紹:https://blog.csdn.net/victorwux/article/details/80466853
volatile關(guān)鍵字原理:https://www.cnblogs.com/wildwolf0/p/11449506.html
3.4 原子類
Java當(dāng)中的原子類:http://www.itdecent.cn/p/b92f0b7da636
3.5 臨界區(qū)
synchronized實(shí)現(xiàn)和Lock實(shí)現(xiàn):http://www.itdecent.cn/p/2089ef4d7f09
3.6 在其它對(duì)象上同步
3.7 線程本地存儲(chǔ)
TheadLocal使用:https://www.zhihu.com/question/341005993/answer/793627819終結(jié)任務(wù)
4.1 裝飾性花園
4.2 在阻塞時(shí)終結(jié)
4.3 中斷
4.4 檢查中斷線程之間的協(xié)作
5.1 wait()與notifyAll()
5.2 notify()與notifyAll()
5.3 生產(chǎn)者與消費(fèi)者
5.4 生產(chǎn)者-消費(fèi)者隊(duì)列
5.5 任務(wù)間使用管道進(jìn)行輸入/輸出死鎖
新類庫中的構(gòu)件
- CountDownLatch
https://www.cnblogs.com/cuglkb/p/8572239.html - CyclicBarrier
http://www.itdecent.cn/p/333fd8faa56e - Semaphore
http://www.itdecent.cn/p/ec637f835e08 - Exchanger
http://www.itdecent.cn/p/990ae2ab1ae0 - DelayQueue
https://baijiahao.baidu.com/s?id=1664636679374249422&wfr=spider&for=pc - PriorityBlockingQueue
https://www.cnblogs.com/yuexiaoyun/p/12203101.html - ArrayBlockingQueue
https://blog.csdn.net/qq_17089617/article/details/80879994 - LinkedBlockingQueue
http://www.itdecent.cn/p/87d230bcc43c - SynchronousQueue
https://blog.csdn.net/yanyan19880509/article/details/52562039 - ScheduledExecutor
http://www.itdecent.cn/p/a39a89d28375
8.其它
- 手動(dòng)實(shí)現(xiàn)線程池
public class MyThreadPool {
//線程池中允許的最大線程數(shù)
private static int MAXTHREDNUM = Integer.MAX_VALUE;
//當(dāng)用戶沒有指定時(shí)默認(rèn)的線程數(shù)
private int threadNum = 6;
//線程隊(duì)列,存放線程任務(wù)
private List<Runnable> queue;
private WorkerThread[] workerThreads;
public MyThreadPool(int threadNum) {
this.threadNum = threadNum;
if (threadNum > MAXTHREDNUM)
threadNum = MAXTHREDNUM;
this.queue = new LinkedList<>();
this.workerThreads = new WorkerThread[threadNum];
init();
}
//初始化線程池中的線程
private void init() {
for (int i = 0; i < threadNum; i++) {
workerThreads[i] = new WorkerThread();
workerThreads[i].start();
}
}
public void execute(Runnable task) {
synchronized (queue) {
queue.add(task);
//提交任務(wù)后喚醒等待在隊(duì)列的線程
queue.notifyAll();
}
}
private class WorkerThread extends Thread {
private volatile boolean on = true;
@Override
public void run() {
Runnable task = null;
// 判斷是否可以取任務(wù)
try {
while (on && !isInterrupted()) {
synchronized (queue) {
while (on && !isInterrupted() && queue.isEmpty()) {
queue.wait(1000);
}
if (on && !isInterrupted() && !queue.isEmpty()) {
task = queue.remove(0);
}
if (task != null) {
// 取到任務(wù)后執(zhí)行
task.run();
}
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
task = null;// 任務(wù)結(jié)束后手動(dòng)置空,加速回收
}
public void cancel() {
on = false;
interrupt();
}
}
public void shutdown() {
for (int i = 0; i < threadNum; i++) {
workerThreads[i].cancel();
workerThreads[i] = null;
}
queue.clear();
}
}