Skip to content

Commit 99903cc

Browse files
committed
add fastdfs
1 parent 201be61 commit 99903cc

Some content is hidden

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

48 files changed

+1261
-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+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.kimmking;
2+
3+
import org.aopalliance.intercept.MethodInterceptor;
4+
import org.aopalliance.intercept.MethodInvocation;
5+
6+
public class DemoMethodIncepter implements MethodInterceptor {
7+
8+
public Object invoke(MethodInvocation invocation) throws Throwable {
9+
10+
long s = System.currentTimeMillis();
11+
System.out.println(" *****====> " + s + " " + invocation.getMethod().getName());
12+
Object result = invocation.proceed();
13+
System.out.println(" *****====> " + (System.currentTimeMillis() - s) + " ms");
14+
return result;
15+
}
16+
17+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.kimmking.anno;
2+
3+
public class AnnoDemo {
4+
5+
public static void main(String[] args) {
6+
7+
}
8+
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package io.kimmking.anno;
2+
3+
4+
public interface IA1 {
5+
6+
void a1();
7+
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.kimmking.anno;
2+
3+
4+
@IAnnotation
5+
public interface IA2 extends IA1 {
6+
7+
void a2();
8+
9+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.kimmking.anno;
2+
3+
4+
import java.lang.annotation.ElementType;
5+
import java.lang.annotation.Retention;
6+
import java.lang.annotation.RetentionPolicy;
7+
import java.lang.annotation.Target;
8+
9+
@Target({ElementType.TYPE})
10+
@Retention(RetentionPolicy.RUNTIME)
11+
public @interface IAnnotation {
12+
}

0 commit comments

Comments
 (0)