Skip to content

Commit 9a6757f

Browse files
authored
Merge pull request #1 from JavaCourse00/main
同步源代码
2 parents 21f061f + 7017134 commit 9a6757f

File tree

58 files changed

+1567
-32
lines changed

Some content is hidden

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

58 files changed

+1567
-32
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ hs_err_pid*
2424
*.iml
2525
*.idea/
2626

27+
out/
2728
classes/
2829
target/
2930
build/
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
package com.example.demo;
2-
3-
import org.junit.jupiter.api.Test;
4-
import org.springframework.boot.test.context.SpringBootTest;
5-
6-
@SpringBootTest
7-
class DemoApplicationTests {
8-
9-
@Test
10-
void contextLoads() {
11-
}
12-
13-
}
1+
//package com.example.demo;
2+
//
3+
//import org.junit.jupiter.api.Test;
4+
//import org.springframework.boot.test.context.SpringBootTest;
5+
//
6+
//@SpringBootTest
7+
//class DemoApplicationTests {
8+
//
9+
// @Test
10+
// void contextLoads() {
11+
// }
12+
//
13+
//}

01jvm/out/production/01jvm/README.md

Lines changed: 85 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
## 作业内容
77

88

9-
> Week01 作业题目(周四)
9+
> Week01 作业题目:
1010
1111
1.(选做)自己写一个简单的 Hello.java,里面需要涉及基本类型,四则运行,if 和 for,然后自己分析一下对应的字节码,有问题群里讨论。
1212

@@ -18,24 +18,102 @@
1818

1919
注意:如果没有线上系统,可以自己 run 一个 web/java 项目。
2020

21-
> Week01 作业题目(周六):
21+
5.(选做)本机使用 G1 GC 启动一个程序,仿照课上案例分析一下 JVM 情况。
2222

23-
1.(选做)本机使用 G1 GC 启动一个程序,仿照课上案例分析一下 JVM 情况。
2423

2524

2625
## 操作步骤
2726

2827

29-
### 作业2
28+
### 作业1(选做)
29+
30+
1. 编写代码, 根据自己的意愿随意编写, 可参考: [Hello.java](./Hello.java)
31+
2. 编译代码, 执行命令: `javac -g Hello.java`
32+
3. 查看反编译的代码。
33+
- 3.1 可以安装并使用idea的jclasslib插件, 选中 [Hello.java](./Hello.java) 文件, 选择 `View --> Show Bytecode With jclasslib` 即可。
34+
- 3.2 或者直接通过命令行工具 javap, 执行命令: `javap -v Hello.class`
35+
4. 分析相关的字节码。【此步骤需要各位同学自己进行分析】
36+
37+
38+
### 作业2(必做)
3039

3140
1. 打开 Spring 官网: https://spring.io/
3241
2. 找到 Projects --> Spring Initializr: https://start.spring.io/
3342
3. 填写项目信息, 生成 maven 项目; 下载并解压。
3443
4. Idea或者Eclipse从已有的Source导入Maven项目。
35-
5. 增加课程资源 Hello.xlass 文件到 src/main/resources 目录。
36-
6. 编写代码,实现 findClass 方法,解码方法
44+
5. 从课件资料中找到资源 Hello.xlass 文件并复制到 src/main/resources 目录。
45+
6. 编写代码,实现 findClass 方法,以及对应的解码方法
3746
7. 编写main方法,调用 loadClass 方法;
3847
8. 创建实例,以及调用方法
3948
9. 执行.
4049

41-
具体的参见: [https://github.com/renfufei/JAVA-000/blob/main/Week_01/homework01/src/main/java/com/renfufei/homework01/XlassLoader.java](XlassLoader.java)
50+
具体代码可参考: [XlassLoader.java](./XlassLoader.java)
51+
52+
53+
### 作业3(必做)
54+
55+
对应的图片需要各位同学自己绘制,可以部分参考PPT课件。
56+
57+
提示:
58+
59+
- Xms 设置堆内存的初始值
60+
- Xmx 设置堆内存的最大值
61+
- Xmn 设置堆内存中的年轻代的最大值
62+
- Meta 区不属于堆内存, 归属为非堆
63+
- DirectMemory 直接内存, 属于 JVM 内存中开辟出来的本地内存空间。
64+
- Xss设置的是单个线程栈的最大空间;
65+
66+
JVM进程空间中的内存一般来说包括以下这些部分:
67+
68+
- 堆内存(Xms ~ Xmx) = 年轻代(~Xmn) + 老年代
69+
- 非堆 = Meta + CodeCache + ...
70+
- Native内存 = 直接内存 + Native + ...
71+
- 栈内存 = n * Xss
72+
73+
另外,注意区分规范与实现的区别, 需要根据具体实现以及版本, 才能确定。 一般来说,我们的目的是为了排查故障和诊断问题,大致弄清楚这些参数和空间的关系即可。 具体设置时还需要留一些冗余量。
74+
75+
76+
### 4.(选做)
77+
78+
这个是具体案例分析, 请各位同学自己分析。
79+
80+
比如我们一个生产系统应用的启动参数为:
81+
82+
```
83+
JAVA_OPTS=-Xmx200g -Xms200g -XX:+UnlockExperimentalVMOptions -XX:+UseZGC -XX:ZCollectionInterval=30 -XX:ZAllocationSpikeTolerance=5 -XX:ReservedCodeCacheSize=2g -XX:InitialCodeCacheSize=2g -XX:ConcGCThreads=8 -XX:ParallelGCThreads=16
84+
```
85+
86+
另一个系统的启动参数为:
87+
88+
```
89+
JAVA_OPTS=-Xmx4g -Xms4g -XX:+UseG1GC -XX:MaxGCPauseMillis=50
90+
```
91+
92+
具体如何设置, 需要考虑的因素包括:
93+
94+
- 系统容量: 业务规模, 并发, 成本预算; 需要兼顾性能与成本;
95+
- 延迟要求: 最坏情况下能接受多少时间的延迟尖刺。
96+
- 吞吐量: 根据业务特征来确定, 比如, 网关, 大数据底层平台, 批处理作业系统, 在线实时应用, 他们最重要的需求不一样。
97+
- 系统架构: 比如拆分为小内存更多节点, 还是大内存少量节点。
98+
- 其他...
99+
100+
101+
### 5.(选做)
102+
103+
例如使用以下命令:
104+
105+
```
106+
# 编译
107+
javac -g GCLogAnalysis.java
108+
# JDK8 启动程序
109+
java -Xmx2g -Xms2g -XX:+UseG1GC -verbose:gc -XX:+PrintGCDateStamps -XX:+PrintGCDetails -Xloggc:gc.log GCLogAnalysis
110+
```
111+
112+
尝试使用课程中介绍的各种工具JDK命令行和图形工具来进行分析。
113+
114+
其中 [GCLogAnalysis.java](./GCLogAnalysis.java) 文件也可以从课件资料zip中找到.
115+
116+
## 更多资料
117+
118+
更多中英文的技术文章和参考资料: <https://github.com/cncounter/translation>
119+

02nio/nio01/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@
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>3.12.0</version>
66+
</dependency>
67+
<dependency>
68+
<groupId>org.apache.httpcomponents</groupId>
69+
<artifactId>httpclient</artifactId>
70+
<version>4.5.5</version>
71+
</dependency>
6272
</dependencies>
6373

6474

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package java0.nio01;
2+
3+
import org.apache.http.HttpEntity;
4+
import org.apache.http.client.methods.CloseableHttpResponse;
5+
import org.apache.http.client.methods.HttpGet;
6+
import org.apache.http.impl.client.CloseableHttpClient;
7+
import org.apache.http.impl.client.HttpClients;
8+
import org.apache.http.protocol.HTTP;
9+
import org.apache.http.util.EntityUtils;
10+
11+
import java.io.IOException;
12+
13+
public class HttpClientDemo {
14+
15+
public static void main(String[] args) throws IOException {
16+
17+
byte[] bytes = getBody1( "http://localhost:8801");
18+
System.out.println(new String(bytes));
19+
20+
}
21+
22+
private static byte[] getBody1(String url){
23+
HttpGet httpGet = new HttpGet(url);
24+
httpGet.setHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
25+
CloseableHttpClient httpClient = null;
26+
CloseableHttpResponse response = null;
27+
try {
28+
httpClient = HttpClients.createDefault();
29+
response = httpClient.execute(httpGet);
30+
HttpEntity entity = response.getEntity();
31+
// System.out.println(EntityUtils.toString(entity));
32+
return EntityUtils.toByteArray(entity);
33+
} catch (IOException e) {
34+
e.printStackTrace();
35+
} finally {
36+
try {
37+
// 释放资源
38+
if (response != null) {
39+
response.close();
40+
}
41+
if (httpClient != null) {
42+
httpClient.close();
43+
}
44+
httpGet.releaseConnection();
45+
} catch (IOException e) {
46+
e.printStackTrace();
47+
}
48+
}
49+
return null;
50+
}
51+
}

02nio/nio01/src/main/java/java0/nio01/HttpServer01.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ private static void service(Socket socket) {
2828
printWriter.println("Content-Length:" + body.getBytes().length);
2929
printWriter.println();
3030
printWriter.write(body);
31+
printWriter.flush();
3132
printWriter.close();
3233
socket.close();
3334
} catch (Exception e) {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package java0.nio01;
2+
3+
import okhttp3.OkHttpClient;
4+
import okhttp3.Request;
5+
import okhttp3.Response;
6+
7+
import java.io.IOException;
8+
9+
public class OKHttpClientDemo {
10+
11+
private static OkHttpClient client = new OkHttpClient();
12+
public static void main(String[] args) throws IOException {
13+
14+
getBody1(client, "http://localhost:8801");
15+
client = null;
16+
}
17+
18+
private static void getBody1(OkHttpClient client, String url){
19+
20+
Request request = new Request.Builder()
21+
.get()
22+
.url(url)
23+
.build();
24+
//String body = "test";
25+
try {
26+
Response response = client.newCall(request).execute();
27+
String responseData = response.body().string();
28+
System.out.println(responseData);
29+
} catch (IOException e) {
30+
e.printStackTrace();
31+
}finally {
32+
client = null;
33+
}
34+
}
35+
}

04fx/dtx01/pom.xml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.0.9.RELEASE</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>io.kimmking</groupId>
12+
<artifactId>dtx01</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>dtx01</name>
15+
<description>Demo project for Spring Boot</description>
16+
17+
<properties>
18+
<java.version>1.8</java.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter-jdbc</artifactId>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter</artifactId>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot-starter-web</artifactId>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.mybatis.spring.boot</groupId>
36+
<artifactId>mybatis-spring-boot-starter</artifactId>
37+
<version>2.1.4</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>mysql</groupId>
41+
<artifactId>mysql-connector-java</artifactId>
42+
<version>5.1.47</version>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>org.apache.dubbo</groupId>
47+
<artifactId>dubbo</artifactId>
48+
<version>2.7.8</version>
49+
</dependency>
50+
51+
<dependency>
52+
<groupId>org.projectlombok</groupId>
53+
<artifactId>lombok</artifactId>
54+
</dependency>
55+
<!-- <dependency>-->
56+
<!-- <groupId>org.springframework.boot</groupId>-->
57+
<!-- <artifactId>spring-boot-starter-cache</artifactId>-->
58+
<!-- </dependency>-->
59+
<!-- <dependency>-->
60+
<!-- <groupId>org.springframework.boot</groupId>-->
61+
<!-- <artifactId>spring-boot-starter-data-redis</artifactId>-->
62+
<!-- </dependency>-->
63+
<!-- <dependency>-->
64+
<!-- <groupId>io.lettuce</groupId>-->
65+
<!-- <artifactId>lettuce-core</artifactId>-->
66+
<!-- </dependency>-->
67+
<!-- <dependency>-->
68+
<!-- <groupId>org.apache.commons</groupId>-->
69+
<!-- <artifactId>commons-pool2</artifactId>-->
70+
<!-- </dependency>-->
71+
<!-- <dependency>-->
72+
<!-- <groupId>net.sf.ehcache</groupId>-->
73+
<!-- <artifactId>ehcache</artifactId>-->
74+
<!-- <version>2.8.3</version>-->
75+
<!-- </dependency>-->
76+
<!-- <dependency>-->
77+
<!-- <groupId>org.mybatis</groupId>-->
78+
<!-- <artifactId>mybatis-ehcache</artifactId>-->
79+
<!-- <version>1.0.0</version>-->
80+
<!-- </dependency>-->
81+
82+
<dependency>
83+
<groupId>org.springframework.boot</groupId>
84+
<artifactId>spring-boot-starter-test</artifactId>
85+
<scope>test</scope>
86+
<exclusions>
87+
<exclusion>
88+
<groupId>org.junit.vintage</groupId>
89+
<artifactId>junit-vintage-engine</artifactId>
90+
</exclusion>
91+
</exclusions>
92+
</dependency>
93+
94+
<!-- <dependency>-->
95+
<!-- <groupId>io.seata</groupId>-->
96+
<!-- <artifactId>seata-all</artifactId>-->
97+
<!-- <version>1.4.2</version>-->
98+
<!-- </dependency>-->
99+
100+
<!-- <dependency>-->
101+
<!-- <groupId>org.dromara</groupId>-->
102+
<!-- <artifactId>hmily-annotation</artifactId>-->
103+
<!-- <version>2.1.1</version>-->
104+
<!-- </dependency>-->
105+
106+
</dependencies>
107+
108+
<build>
109+
<plugins>
110+
<plugin>
111+
<groupId>org.springframework.boot</groupId>
112+
<artifactId>spring-boot-maven-plugin</artifactId>
113+
</plugin>
114+
</plugins>
115+
</build>
116+
117+
</project>

0 commit comments

Comments
 (0)