Skip to content

Commit de00159

Browse files
authored
Merge pull request #1 from JavaCourse00/main
1
2 parents 01d9794 + 60d2f74 commit de00159

File tree

82 files changed

+2729
-33
lines changed

Some content is hidden

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

82 files changed

+2729
-33
lines changed

01jvm/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# 第1周作业
2+
3+
4+
参见 我的教室 -> 本周作业
5+
6+
## 作业内容
7+
8+
9+
> Week01 作业题目(周四):
10+
11+
1.(选做)自己写一个简单的 Hello.java,里面需要涉及基本类型,四则运行,if 和 for,然后自己分析一下对应的字节码,有问题群里讨论。
12+
13+
2.(必做)自定义一个 Classloader,加载一个 Hello.xlass 文件,执行 hello 方法,此文件内容是一个 Hello.class 文件所有字节(x=255-x)处理后的文件。文件群里提供。
14+
15+
3.(必做)画一张图,展示 Xmx、Xms、Xmn、Meta、DirectMemory、Xss 这些内存参数的关系。
16+
17+
4.(选做)检查一下自己维护的业务系统的 JVM 参数配置,用 jstat 和 jstack、jmap 查看一下详情,并且自己独立分析一下大概情况,思考有没有不合理的地方,如何改进。
18+
19+
注意:如果没有线上系统,可以自己 run 一个 web/java 项目。
20+
21+
> Week01 作业题目(周六):
22+
23+
1.(选做)本机使用 G1 GC 启动一个程序,仿照课上案例分析一下 JVM 情况。
24+
25+
26+
## 操作步骤
27+
28+
29+
### 作业2
30+
31+
1. 打开 Spring 官网: https://spring.io/
32+
2. 找到 Projects --> Spring Initializr: https://start.spring.io/
33+
3. 填写项目信息, 生成 maven 项目; 下载并解压。
34+
4. Idea或者Eclipse从已有的Source导入Maven项目。
35+
5. 增加课程资源 Hello.xlass 文件到 src/main/resources 目录。
36+
6. 编写代码,实现 findClass 方法,解码方法
37+
7. 编写main方法,调用 loadClass 方法;
38+
8. 创建实例,以及调用方法
39+
9. 执行.
40+
41+
具体的参见: [https://github.com/renfufei/JAVA-000/blob/main/Week_01/homework01/src/main/java/com/renfufei/homework01/XlassLoader.java](XlassLoader.java)

02nio/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# 第2周作业
2+
3+
4+
## 作业内容
5+
6+
> Week02 作业题目(周四):
7+
8+
1.使用 GCLogAnalysis.java 自己演练一遍串行 / 并行 /CMS/G1 的案例。
9+
2.使用压测工具(wrk 或 sb),演练 gateway-server-0.0.1-SNAPSHOT.jar 示例。
10+
3.(选做) 如果自己本地有可以运行的项目,可以按照 2 的方式进行演练。
11+
4.(必做) 根据上述自己对于 1 和 2 的演示,写一段对于不同 GC 的总结,提交到 Github。
12+
13+
> Week02 作业题目(周六):
14+
15+
1.(选做)运行课上的例子,以及 Netty 的例子,分析相关现象。
16+
17+
2.(必做)写一段代码,使用 HttpClient 或 OkHttp 访问 http://localhost:8801 ,代码提交到 Github。
18+
19+
20+
## 操作步骤
21+
22+
23+
### 第二周-周六-作业2
24+
25+
1. 打开 Spring 官网: https://spring.io/
26+
2. 找到 Projects --> Spring Initializr: https://start.spring.io/
27+
3. 填写项目信息, 生成 maven 项目; 下载并解压。
28+
4. Idea或者Eclipse从已有的Source导入Maven项目。
29+
5. 搜索依赖, 推荐 mvnrepository: https://mvnrepository.com/
30+
6. 搜索 OkHttp 或者 HttpClient,然后在 pom.xml 之中增加对应的依赖。
31+
7. 使用OkHttp
32+
- 7.1 查找OkHttp官网: https://square.github.io/okhttp/
33+
- 7.2 参照官方示例编写代码: [OkHttpUtils.java](https://github.com/renfufei/JAVA-000/blob/main/Week_02/homework02/src/main/java/com/renfufei/homework02/OkHttpUtils.java)
34+
8. 使用HttpClient
35+
- 8.1 查找官网: http://hc.apache.org/
36+
- 8.2 参照官方示例编写代码: [HttpClientHelper.java](https://github.com/renfufei/JAVA-000/blob/main/Week_02/homework02/src/main/java/com/renfufei/homework02/HttpClientHelper.java)
37+
- 8.3 执行如果报错, 根据提示,增加 commons-logging 或者其他日志依赖。
38+
9. 执行与测试.

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/src/main/java/java0/conc0301/DaemonThread.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void run() {
1717
};
1818
Thread thread = new Thread(task);
1919
thread.setName("test-thread-1");
20-
thread.setDaemon(true);
20+
thread.setDaemon(false);
2121
thread.start();
2222
}
2323

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ public void run() {
1111
boolean result = Thread.currentThread().isInterrupted();
1212

1313
boolean result1 = Thread.interrupted(); // 重置状态
14-
14+
1515
boolean result3 = Thread.currentThread().isInterrupted();
1616

1717
System.out.println("Runner2.run result ===>" + result);
1818
System.out.println("Runner2.run result1 ===>" + result1);
1919
System.out.println("Runner2.run result3 ===>" + result3);
20+
21+
2022
}
2123
}
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11

22
package java0.conc0301;
33

4+
import java.io.IOException;
5+
46
public class RunnerMain {
57

6-
public static void main(String[] args) {
8+
public static void main(String[] args) throws IOException {
79

810
Runner1 runner1 = new Runner1();
911
Thread thread1 = new Thread(runner1);
@@ -14,12 +16,14 @@ public static void main(String[] args) {
1416
thread1.start();
1517
thread2.start();
1618

17-
thread2.interrupt();
19+
thread2.interrupt(); // i = true
1820

1921
System.out.println(Thread.activeCount());
2022

21-
// Thread.currentThread().getThreadGroup().list();
22-
// System.out.println(Thread.currentThread().getThreadGroup().getParent().activeGroupCount());
23-
// Thread.currentThread().getThreadGroup().getParent().list();
23+
Thread.currentThread().getThreadGroup().list();
24+
System.out.println(Thread.currentThread().getThreadGroup().getParent().activeGroupCount());
25+
Thread.currentThread().getThreadGroup().getParent().list();
26+
27+
2428
}
2529
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public void run() {
1515
String currentThreadName = currentThread.getName();
1616

1717
System.out.println("这是线程的名称:" + currentThreadName);
18-
System.out.println("返回当前线程" + currentThreadName + "的线程组中活动线程的数量:" + Thread.activeCount());
18+
System.out.println("返回当前线程" + currentThreadName + "的线程组中活动线程的数量:" + Thread.currentThread().getThreadGroup().activeCount());
1919
System.out.println("返回该线程" + currentThreadName + "的标识符:" + currentThread.getId());
2020
System.out.println("返回该线程" + currentThreadName + "的优先级:" + currentThread.getPriority());
2121
System.out.println("返回该线程" + currentThreadName + "的状态:" + currentThread.getState());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static void main(String[] args) {
1515
new Thread(threadB).start();
1616
System.out.println("这是主线程:");
1717

18-
ThreadC threadC = new ThreadC();
18+
ThreadC threadC = new ThreadC();
1919
FutureTask<String> futureTask = new FutureTask<>(threadC);
2020
new Thread(futureTask).start();
2121
System.out.println("这是主线程:begin!");

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public static void main(String[] args) {
99
thread1.setOo(oo);
1010
thread1.start();
1111

12-
synchronized (oo) {
12+
synchronized (thread1) {
1313
for (int i = 0; i < 100; i++) {
1414
if (i == 20) {
1515
try {
@@ -40,7 +40,7 @@ public MyThread(String name) {
4040

4141
@Override
4242
public void run() {
43-
synchronized (oo) {
43+
synchronized (this) {
4444
for (int i = 0; i < 100; i++) {
4545
System.out.println(name + i);
4646
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ public static void main(String[] args) {
1919
e.printStackTrace();
2020
}
2121
}, "t2");
22-
Thread t3 = new Thread(() -> {
23-
try {
24-
methodClass.customer();
25-
} catch (InterruptedException e) {
26-
// TODO Auto-generated catch block
27-
e.printStackTrace();
28-
}
29-
}, "t3");
22+
// Thread t3 = new Thread(() -> {
23+
// try {
24+
// methodClass.customer();
25+
// } catch (InterruptedException e) {
26+
// // TODO Auto-generated catch block
27+
// e.printStackTrace();
28+
// }
29+
// }, "t3");
3030
t1.start();
3131
t2.start();
32-
t3.start();
32+
//t3.start();
3333

3434
}
3535
}

0 commit comments

Comments
 (0)