---
# System prepended metadata

title: '**Java Concurrent Programming**'
tags: [' java', computer science]

---

---
tags: computer science, java
---

<center>

# **Java Concurrent Programming**

:::info
Location: Room 108, 德田館
Time: 1300 ~ 1600
:::

</center>

<div style="text-align: right">``xxx''<br>-- xxx</div>

## **Class Information**

### Instructor
- Name: 盧政良 (Zheng-Liang Lu, Arthur)
- Email: arthurzllu@gmail.com

### Objectives
- Comprehend design patterns widely used in large-scale projects
- Learn generics, annotations, and reflection, Stream APIs (with lambdas), and Optional APIs
- Start your first web application powered by Spring Boot
- Exploit concurrent programming with Concurrency API

### Prerequisites
- Java Programming [link](https://www.csie.ntu.edu.tw/~d00922011/java.html)

### Working Environment
- JDK8+ with Eclipse

### Recording Classroom Lectures Policy
:::warning
Recording of classroom lectures is <font color="red">**prohibited**</font> unless advance written permission is obtained from the class instructor and any guest presenter(s).
:::

## **Overview**

### Concurrent Programming
- Java Virtual Machine (JVM)
- Basic concepts of operating systems (OS)
    - Process & thread
    - Job scheduling: round-robin (RR)
- Thread & Runnable
- Race condition, mutual exclusion & synchronized methods/blocks
- Producer-consumer problem (bounded-buffer problem) & semaphores
- Dining philosophers: deadlock, livelock, starvation
- High-level concurrency framework:
    - Thread pools
    - Fork-join pools
    - Asynchronous computation
    - Concurrent data structures, atomic variables, synchronizers, monitor locks

## **Schedule**

### ++Concurrent Programming++
- Basics of operating systems (OS)
    - Jerry Breecher, <a href="https://web.cs.wpi.edu/~cs3013/c07/lectures/Section03-Processes.pdf">processes</a> and <a href="https://web.cs.wpi.edu/~cs3013/c07/lectures/Section04-Threads.pdf">threads</a>
	- (FYR) Jserv, <a href = "https://hackmd.io/@sysprog/linux-concepts">Linux 核心設計: 作業系統術語及概念</a>, 2020
    - Remzi H. Arpaci-Dusseau and Andrea C. Arpaci-Dusseau, <a href = "http://pages.cs.wisc.edu/~remzi/OSTEP/">Operating Systems: Three Easy Pieces</a>, 2018 (online version)
    - (FYR) Virtual memory
        - Elaine's Blog , [CH8 記憶體管理 (Memory Management Strategies)](https://kim85326.github.io/2018/01/09/CH8-%E8%A8%98%E6%86%B6%E9%AB%94%E7%AE%A1%E7%90%86-(Memory-Management-Strategies)/), 2018.1.9
        - Elaine's Blog , [CH9 虛擬記憶體管理 (Virtual-Memory Management)](https://kim85326.github.io/2018/01/09/CH9-%E8%99%9B%E6%93%AC%E8%A8%98%E6%86%B6%E9%AB%94%E7%AE%A1%E7%90%86-(Virtual-Memory-Management)/), 2018.1.9
        - Translation lookaside buffer (TLB) https://en.wikipedia.org/wiki/Translation_lookaside_buffer
- Java threads [pdf](https://www.csie.ntu.edu.tw/~d00922011/java2/multithreading/JavaThreads.pdf)
    - (FYR) Java concurreny tutorial [link](https://docs.oracle.com/javase/tutorial/essential/concurrency/)
    - Race condition: [code](https://www.csie.ntu.edu.tw/~d00922011/java2/multithreading/RaceConditionDemo.zip)
        - https://people.engr.tamu.edu/hlee42/csce314/lec17-JVM.pdf
    - Parallelism is always good? [code](https://www.csie.ntu.edu.tw/~d00922011/java2/multithreading/MapReduceDemo.java) and [Amdahl's law](https://en.wikipedia.org/wiki/Amdahl%27s_law)</li>
    - Application (feat. parallel stream) [code](https://www.csie.ntu.edu.tw/~d00922011/java2/multithreading/MonteCarloMultiThreadDemo.zip)
- Sychronization [pdf](https://www.csie.ntu.edu.tw/~d00922011/java2/multithreading/Synchronisation.pdf) [code](https://www.csie.ntu.edu.tw/~d00922011/java2/multithreading/SemaphoreDemo.java)
    - Jserv, [作業系統概念: Concurrency 程式設計篇](https://youtu.be/3mkug2ygdIs)
    - Linus Torvalds, a reply to discussion about spinlock implementation and Linux scheduler ([1](https://www.realworldtech.com/forum/?threadid=189711&curpostid=189723), [2](https://www.realworldtech.com/forum/?threadid=189711&curpostid=189752), [3](https://www.realworldtech.com/forum/?threadid=189711&curpostid=189755), [4](https://www.realworldtech.com/forum/?threadid=189711&curpostid=189759)), 2020.1.3 (also read [news](https://www.ithome.com.tw/news/135226))
    - (FYR) [How to implement synchronized methods/blocks in Java?](https://www.itread01.com/content/1544398054.html), 2018
    - (FYR) [An Introduction to Lock-Free Programming](https://preshing.com/20120612/an-introduction-to-lock-free-programming/), 2012
- Concurrent application [pdf](https://www.csie.ntu.edu.tw/~d00922011/java2/multithreading/MultithradedServer.pdf) [code](https://www.csie.ntu.edu.tw/~d00922011/java2/multithreading/client_server_model_sample.zip)
    - More Java socket programming examples: [link](https://cs.lmu.edu/~ray/notes/javanetexamples/)
- Java concurrency framework 
    - Popcorny Lu, [Java 多執行緒的基本知識](https://popcornylu.gitbooks.io/java_multithread/content/) [code](https://www.csie.ntu.edu.tw/~d00922011/java2/multithreading/ConcurrentFramework.zip)
        - 20 Examples of Using Java’s CompletableFuture [link](https://dzone.com/articles/20-examples-of-using-javas-completablefuture)
        - Multi-Threading in Spring Boot Using CompletableFuture [link](https://dzone.com/articles/multi-threading-in-spring-boot-using-completablefu)
- (FYR) Dmitry Aleksandrov, Programming the GPU in Java, 2020 [link](https://blogs.oracle.com/javamagazine/programming-the-gpu-in-java)

## **References**

### ++Concurrent Programming++
- Brian Goetz, [Java Concurrency in Practice](https://www.amazon.com/Java-Concurrency-Practice-Brian-Goetz/dp/0321349601), 2006
![](https://i.imgur.com/syDGooT.png =100x)
- Maurice Herlihy, Nir Shavit, Victor Luchangco, and Michael Spear, [The Art of Multiprocessor Programming](https://www.amazon.com/Art-Multiprocessor-Programming-Maurice-Herlihy/dp/0124159508/), 2/e, 2020
![](https://i.imgur.com/XC22Jsp.png =110x)
- Carlo A. Furia, [Concurrent Programming - TDA383/DIT390](http://www.cse.chalmers.se/edu/year/2016/course/TDA383_LP3/), Chalmers University of Technology, 2017
- Shan He, [SSC: Networks/Concurrency 2014/2015](https://www.cs.bham.ac.uk/~szh/teaching/ssc/), School of Computer Science, University of Birmingham
- Jeff Preshing, [An Introduction to Lock-Free Programming](https://preshing.com/20120612/an-introduction-to-lock-free-programming/), 2012
- Liam O'Connor, [COMP3151/9154 Foundations of Concurrency](http://www.cse.unsw.edu.au/~cs3151/20T2/), 2020

### ++Parallel Computing++
- [Introduction to Parallel Computing Tutorial](https://hpc.llnl.gov/training/tutorials/introduction-parallel-computing-tutorial )
- [POSIX Threads Programming](https://hpc-tutorials.llnl.gov/posix/)
- [OpenMP Tutorial](https://hpc.llnl.gov/openmp-tutorial)
 
#### Operating System
- https://www.linux.org/
![](https://i.imgur.com/tRyM5V8.png)
- Jserv, [Linux Kernel Internals](http://wiki.csie.ncku.edu.tw/linux/schedule), NCKU [fb](https://www.facebook.com/groups/system.software2021/)