8000 Merge pull request #1 from kimmking/main · JavaCourse00/JavaCourseCodes@c20dcc3 · GitHub
[go: up one dir, main page]

Skip to content

Commit c20dcc3

Browse files
authored
Merge pull request #1 from kimmking/main
get latest code
2 parents 48d0adf + 436102c commit c20dcc3

Some content is hidden

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

60 files changed

+2219
-0
lines changed

02nio/nio02/src/main/java/io/github/kimmking/gateway/router/HttpEndpointRouter.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,12 @@ public interface HttpEndpointRouter {
66

77
String route(List<String> endpoints);
88

9+
// Load Balance
10+
// Random
11+
// RoundRibbon
12+
// Weight
13+
// - server01,20
14+
// - server02,30
15+
// - server03,50
16+
917
}

03concurrency/0301/pom.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>java0.03concurrency</groupId>
8+
<artifactId>0301</artifactId>
9+
<version>1.0</version>
10+
<build>
11+
<plugins>
12+
<plugin>
13+
<groupId>org.apache.maven.plugins</groupId>
14+
<artifactId>maven-compiler-plugin</artifactId>
15+
<configuration>
16+
<source>8</source>
17+
<target>8</target>
18+
</configuration>
19+
</plugin>
20+
</plugins>
21+
</build>
22+
23+
24+
</project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package java0.conc0301;
2+
3+
public class DaemonThread {
4+
5+
public static void main(String[] args) {
6+
Runnable task = new Runnable() {
7+
@Override
8+
public void run() {
9+
try {
10+
Thread.sleep(5000);
11+
} catch (InterruptedException e) {
12+
e.printStackTrace();
13+
}
14+
Thread t = Thread.currentThread();
15+
System.out.println("当前线程:" + t.getName());
16+
}
17+
};
18+
Thread thread = new Thread(task);
19+
thread.setName("test-thread-1");
20+
thread.setDaemon(false);
21+
thread.start();
22+
}
23+
24+
25+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package java0.conc0301;
2+
3+
public class Runner1 implements Runnable {
4+
5+
@Override
6+
public void run() {
7+
for (int i = 0; i < 100; i++) {
8+
System.out.println("进入Runner1运行状态——————————" + i);
9+
}
10+
}
11+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package java0.conc0301;
2+
3+
public class Runner2 implements Runnable {
4+
5+
@Override
6+
public void run() {
7+
for (int i = 0; i < 100; i++) {
8+
System.out.println("进入Runner2运行状态——————————" + i);
9+
}
10+
11+
boolean result = Thread.currentThread().isInterrupted();
12+
13+
boolean result1 = Thread.interrupted(); // 重置状态
14+
15+
boolean result3 = Thread.currentThread().isInterrupted();
16+
17+
System.out.println("Runner2.run result ===>" + result);
18+
System.out.println("Runner2.run result1 ===>" + result1);
19+
System.out.println("Runner2.run result3 ===>" + result3);
20+
21+
22+
}
23+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
package java0.conc0301;
3+
4+
import java.io.IOException;
5+
6+
public class RunnerMain {
7+
8+
public static void main(String[] args) throws IOException {
9+
10+
Runner1 runner1 = new Runner1();
11+
Thread thread1 = new Thread(runner1);
12+
13+
Runner2 runner2 = new Runner2();
14+
Thread thread2 = new Thread(runner2);
15+
16+
thread1.start();
17+
thread2.start();
18+
19+
thread2.interrupt(); // i = true
20+
21+
System.out.println(Thread.activeCount());
22+
23+
Thread.currentThread().getThreadGroup().list();
24+
System.out.println(Thread.currentThread().getThreadGroup().getParent().activeGroupCount());
25+
Thread.currentThread().getThreadGroup().getParent().list();
26+
27+
28+
}
29+
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package java0.conc0301;
2+
3+
public class ThreadA extends Thread {
4+
5+
public void run() {
6+
super.run();
7+
try {
8+
Thread.sleep(500);
9+
} catch (InterruptedException e) {
10+
e.printStackTrace();
11+
}
12+
System.out.println("这是线程A");
13+
}
14+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package java0.conc0301;
2+
3+
public class ThreadB implements Runnable {
4+
5+
@Override
6+
public void run() {
7+
try {
8+
Thread.sleep(500);
9+
} catch (InterruptedException e) {
10+
e.printStackTrace();
11+
}
12+
System.out.println("这是线程B");
13+
14+
Thread currentThread = Thread.currentThread();
15+
String currentThreadName = currentThread.getName();
16+
17+
System.out.println("这是线程的名称:" + currentThreadName);
18+
System.out.println("返回当前线程" + currentThreadName + "的线程组中活动线程的数量:" + Thread.currentThread().getThreadGroup().activeCount());
19+
System.out.println("返回该线程" + currentThreadName + "的标识符:" + currentThread.getId());
20+
System.out.println("返回该线程" + currentThreadName + "的优先级:" + currentThread.getPriority());
21+
System.out.println("返回该线程" + currentThreadName + "的状态:" + currentThread.getState());
22+
System.out.println("返回该线程" + currentThreadName + "所属的线程组:" + currentThread.getThreadGroup());
23+
System.out.println("测试该线程" + currentThreadName + "是否处于活跃状态:" + currentThread.isAlive());
24+
System.out.println("测试该线程" + currentThreadName + "是否为守护线程:" + currentThread.isDaemon());
25+
}
26+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package java0.conc0301;
2+
3+
import java.util.concurrent.Callable;
4+
5+
public class ThreadC implements Callable<String> {
6+
7+
@Override
8+
public String call() throws Exception {
9+
Thread.sleep(500);
10+
System.out.println("这是线程C");
11+
return "线程C";
12+
}
13+
14+
15+
16+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package java0.conc0301;
2+
3+
import java.util.concurrent.ExecutionException;
4+
import java.util.concurrent.FutureTask;
5+
6+
public class ThreadMain {
7+
8+
public static void main(String[] args) {
9+
10+
ThreadA threadA = new ThreadA();
11+
threadA.start();
12+
System.out.println("这是主线程:");
13+
14+
ThreadB threadB = new ThreadB();
15+
new Thread(threadB).start();
16+
System.out.println("这是主线程:");
17+
18+
ThreadC threadC = new ThreadC();
19+
FutureTask<String> futureTask = new FutureTask<>(threadC);
20+
new Thread(futureTask).start();
21+
System.out.println("这是主线程:begin!");
22+
try {
23+
System.out.println("得到的返回结果是:" + futureTask.get());
24+
} catch (InterruptedException e) {
25+
e.printStackTrace();
26+
} catch (ExecutionException e) {
27+
e.pri 4E6E ntStackTrace();
28+
}
29+
30+
}
31+
32+
}

0 commit comments

Comments
 (0)
0