Skip to content

Commit b091cd5

Browse files
committed
add my comments
1 parent 7bb035d commit b091cd5

43 files changed

Lines changed: 496 additions & 23 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

02nio/nio01/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959
<artifactId>netty-all</artifactId>
6060
<version>4.1.51.Final</version>
6161
</dependency>
62+
<dependency>
63+
<groupId>com.squareup.okhttp3</groupId>
64+
<artifactId>okhttp</artifactId>
65+
<version>4.9.0</version>
66+
</dependency>
6267
</dependencies>
6368

6469

03concurrency/0301/src/main/java/java0/conc0301/DaemonThread.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package java0.conc0301;
22

3+
/**
4+
* 总结:
5+
* JAVA 进程中,如果运行的线程都是 daemon 线程,则进程可以正常结束,
6+
* 如果运行的线程中有非 daemon 线程,则进程需要等待所有的非daemon线程都运行完毕,才能正常结束。
7+
*/
38
public class DaemonThread {
49

510
public static void main(String[] args) throws InterruptedException {

03concurrency/0301/src/main/java/java0/conc0301/Runner2.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package java0.conc0301;
22

3+
/**
4+
* Thread.isInterrupted() 不会重置 Interrupted 状态
5+
* Thread.interrupted() 重置 Interrupted 状态
6+
*/
37
public class Runner2 implements Runnable {
48

59
@Override

03concurrency/0301/src/main/java/java0/conc0301/ThreadCount.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
package java0.conc0301;
22

3+
/**
4+
* 线程信息:
5+
* 在没有业务线程情况下,总共有两个线程组,6个线程(4个系统组的线程,2个主线程组的线程),如下所示:
6+
* java.lang.ThreadGroup[name=system,maxpri=10]
7+
* Thread[Reference Handler,10,system]
8+
* Thread[Finalizer,8,system]
9+
* Thread[Signal Dispatcher,9,system]
10+
* Thread[Attach Listener,5,system]
11+
* java.lang.ThreadGroup[name=main,maxpri=10]
12+
* Thread[main,5,main]
13+
* Thread[Monitor Ctrl-Break,5,main]
14+
*/
315
public class ThreadCount {
416
public static void main(String[] args) throws InterruptedException {
517
//System.out.println("system:"+Thread.currentThread().getThreadGroup().getParent());

03concurrency/0301/src/main/java/java0/conc0301/ThreadMain2.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ public static void main(String[] args) {
99
new Thread(threadB, "线程名称:(" + i + ")").start();
1010
}
1111

12+
Thread.currentThread().getThreadGroup().list();
13+
1214
try {
1315
Thread.sleep(10000);
1416
} catch (InterruptedException e) {
1517
e.printStackTrace();
1618
}
1719

20+
System.out.println("线程组成员:");
21+
1822
//返回对当前正在执行的线程对象的引用
1923
Thread threadMain = Thread.currentThread();
2024
System.out.println("这是主线程:");

03concurrency/0301/src/main/java/java0/conc0301/op/Join.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
/**
44
* 总结:线程A结束的时候,JVM内部会发送通知 notifyAll 给该线程对象A上的等待线程,唤醒在线程对象A上等待的线程
5+
* 其中this 代表线程的执行的task对象。
6+
* JAVA线程可以看作由两部分组成,
7+
* 1. Java Task 对象,由JVM回调执行线程中的任务,即run方法的对象实体。
8+
* 2. 操作系统的线程,一个Java 线程会一对一一个操作系统线程,
9+
* 而Thread 中的 this对象代表Java Task 对象实体,
10+
* Thread.current()返回的线程代表的是操作系统线程
511
*/
612
public class Join {
713

03concurrency/0301/src/main/java/java0/conc0301/sync/Thread1.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Thread 线程对象中的任意方法获取的 this 代表线程对象本身,并不代表线程信息(线程信息中包括操作系统线程)
77
* Thread.currentThread() 代表操作系统对应的线程信息.
88
* 所以 this != Thread.currentThread() ,this 代表 Task 对象信息
9-
* 如下所示:TA 线程和 TB线程在操作系统上创建了两个线程对应 A线程 和 B线程,但是它们公用一个Task 对象信息, this是 task 对象信息
9+
* 如下所示:TA 线程和 TB线程在操作系统上创建了两个操作系统线程对应 A线程 和 B线程,但是它们公用一个Task 对象信息, this是 task 对象信息
1010
*/
1111
public class Thread1 implements Runnable {
1212

03concurrency/0301/src/main/java/java0/conc0301/sync/Thread2.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11

22
package java0.conc0301.sync;
33

4+
/**
5+
* 总结:
6+
* 两个Java Thread 对应两个操作系统线程,同时同享一个java task 对象实例
7+
*/
48
public class Thread2 {
59

610
public void m4t1() {

03concurrency/0301/src/main/java/java0/conc0301/sync/Thread3.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ private void m4t1() {
1414
}
1515
}
1616

17-
private void m4t2() {
17+
private synchronized void m4t2() {
1818
int i = 5;
1919
while (i-- > 0) {
2020
System.out.println(Thread.currentThread().getName() + " : Inner.m4t2()=" + i);

03concurrency/0301/src/main/java/java0/conc0302/atomic/AtomicCount.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import java.util.concurrent.atomic.AtomicInteger;
55

6-
public class AtomicCount {
6+
public class AtomicCount implements CountInf {
77

88
private AtomicInteger num = new AtomicInteger();
99

0 commit comments

Comments
 (0)