Skip to content

Commit 28bba38

Browse files
committed
本地调整
1 parent 99313df commit 28bba38

10 files changed

Lines changed: 23 additions & 9 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ public void run() {
99
} catch (InterruptedException e) {
1010
e.printStackTrace();
1111
}
12-
System.out.println("这是线程A");
12+
System.out.println("这是线程A:"+Thread.currentThread().getName());
1313
}
1414
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public class ThreadB implements Runnable {
55
@Override
66
public void run() {
77
try {
8-
Thread.sleep(500);
8+
Thread.sleep(5000);
99
} catch (InterruptedException e) {
1010
e.printStackTrace();
1111
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class ThreadC implements Callable<String> {
77
@Override
88
public String call() throws Exception {
99
Thread.sleep(500);
10-
System.out.println("这是线程C");
10+
System.out.println("这是线程C:"+Thread.currentThread().getName());
1111
return "线程C";
1212
}
1313

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public static void main(String[] args) {
1212
System.out.println("这是主线程:");
1313

1414
ThreadB threadB = new ThreadB();
15+
// threadB.run();
1516
new Thread(threadB).start();
1617
System.out.println("这是主线程:");
1718

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static void main(String[] args) {
1010
}
1111

1212
try {
13-
Thread.sleep(10000);
13+
Thread.sleep(100);
1414
} catch (InterruptedException e) {
1515
e.printStackTrace();
1616
}
@@ -26,6 +26,7 @@ public static void main(String[] args) {
2626
System.out.println("返回该线程所属的线程组:" + threadMain.getThreadGroup());
2727
System.out.println("测试线程是否为守护线程:" + threadMain.isDaemon());
2828

29+
System.out.println(Thread.getAllStackTraces());
2930

3031
// try {
3132
// Thread.sleep(10000);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public static void main(String[] args) {
1414
for (int i = 0; i < 100; i++) {
1515
if (i == 20) {
1616
try {
17-
oo.wait(0);
18-
//thread1.join();
17+
// oo.wait(0); //释放oo锁,跳出循环
18+
thread1.join();//不会释放oo锁,会停在这
1919
} catch (InterruptedException e) {
2020
e.printStackTrace();
2121
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class MethodClass {
4242

4343
public synchronized void product() throws InterruptedException {
4444
while (true) {
45-
System.out.println(Thread.currentThread().getName() + ":::run:::" + productCount);
45+
System.out.println(Thread.currentThread().getName() + ":::product:::" + productCount);
4646
Thread.sleep(10);
4747
if (productCount >= MAX_COUNT) {
4848
System.out.println("货舱已满,,.不必再生产");
@@ -53,12 +53,13 @@ public synchronized void product() throws InterruptedException {
5353
}
5454

5555
notifyAll();
56+
5657
}
5758
}
5859

5960
public synchronized void customer() throws InterruptedException {
6061
while (true) {
61-
System.out.println(Thread.currentThread().getName() + ":::run:::" + productCount);
62+
System.out.println(Thread.currentThread().getName() + ":::consumer:::" + productCount);
6263
Thread.sleep(10);
6364
if (productCount <= 0) {
6465
System.out.println("货舱已无货...无法消费");

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

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

3+
import java.util.concurrent.TimeUnit;
4+
import java.util.concurrent.locks.Condition;
5+
import java.util.concurrent.locks.Lock;
6+
37
public class Counter {
48

59
private int sum = 0;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package java0.conc0302.lock;
2+
3+
public class LockCounter {
4+
}

03concurrency/0301/src/main/java/java0/conc0303/future/CompletableFutureDemo.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package java0.conc0303.future;
22

3+
import java.util.Collections;
4+
import java.util.HashMap;
5+
import java.util.Vector;
36
import java.util.concurrent.CompletableFuture;
47

58
public class CompletableFutureDemo {
69

710
public static void main(String[] args){
8-
11+
912
// 1.变换结果
1013
System.out.println("=====>1.变换结果");
1114
String result1 = CompletableFuture.supplyAsync(()->{return "Hello ";}).thenApplyAsync(v -> v + "world").join();

0 commit comments

Comments
 (0)