Skip to content

Commit bb588b1

Browse files
committed
线程代码提交
1 parent 09aa3b7 commit bb588b1

42 files changed

Lines changed: 1574 additions & 13 deletions

Some content is hidden

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

city.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?><china>
2+
<guangzhou play="gzchanglong">广州你好</guangzhou>
3+
<shenzhen>深圳</shenzhen>
4+
<shanghai>上海</shanghai>
5+
<guangxi>广西</guangxi>
6+
<hangzhou>杭州</hangzhou></china>

dom4j-1.6.1.jar

307 KB
Binary file not shown.

dom4j.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<dom4j>
3+
<name littleName="属性值">dom4j模板</name>
4+
</dom4j>

src/city.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<china>
3+
<guangzhou>广州</guangzhou>
4+
<shenzhen>深圳</shenzhen>
5+
<shanghai>上海</shanghai>
6+
<beijing>北京</beijing>
7+
</china>
681 KB
Loading
616 KB
Loading
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.yale.test.run;
2+
3+
import sun.misc.Cleaner;
4+
5+
/**
6+
* 但是从JDK1.9开始,这一操作已经不建议使用了,而对于对象回收释放.从JDK1.9开始建议开发者使用AutoCloseable
7+
* 或者使用java.lang.ref.Cleaner类进行回收(Cleaner也支持有AutoCloseable处理).
8+
* Cleaner实际上是重新启用一个线程来做回收的
9+
* 在新一代的清除回收处理的过程之中,更过的情况下考虑的是多线程的使用,即:为了防止有可能造成的延迟,
10+
* 所以许多对象回收前的处理都是单独通过一个线程完成的。
11+
*/
12+
public class CleanerTest {
13+
public static void main(String[] args) {
14+
Cleaner cleaner = Cleaner.create();
15+
}
16+
}
Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,58 @@
11
package com.yale.test.run;
22

3+
/**
4+
* Runtime描述的是运行时的状态,也就是说在整个的JVM之中,Runtime类是唯一一个与JVM运行状态有关的类,
5+
* 并且都会默认提供有一个该类的实例化对象。
6+
* 由于在每一个JVM进程里面只允许提供一个Runtime类的对象,所以这个类的构造方法被默认私有化了,那么就证明该类
7+
* 使用的是单例设计模式
8+
* 阿里云 魔乐科技的JAVA教程视频
9+
* https://edu.aliyun.com/lesson_36_446?spm=5176.8764728.0.0.3ead521ct2pu1e#_446
10+
* https://edu.aliyun.com/course/explore/gentech?spm=5176.10731491.category.12.78904d8aB9zl2v&subCategory=java&filter%5Btype%5D=all&filter%5Bprice%5D=all&filter%5BcurrentLevelId%5D=all&orderBy=studentNum&title=
11+
* @author dell
12+
*/
313
public class RunntimeTest {
414

5-
public static void main(String[] args) {
15+
public static void main(String[] args) throws InterruptedException {
16+
RunntimeTest sdf = new RunntimeTest();
17+
sdf = null;//等待垃圾回收
618
Runtime run = Runtime.getRuntime();
7-
System.out.println("最大内存:" + run.maxMemory());
8-
System.out.println("可用内存:" + run.totalMemory());
9-
System.out.println("空余内存:" + run.freeMemory());
10-
19+
System.out.println("获取最大可用内存空间:" + run.maxMemory() + "字节,默认的配置为本机系统内存的4分之1");
20+
System.out.println("获取可用内存空间:" + run.totalMemory() + "字节,默认的配置为本机系统内存的64分之1");
21+
System.out.println("获取空余内存空间:" + run.freeMemory() + "字节");
22+
System.out.println("availableProcessors方法可以获取本机的CPU内核数:" + run.availableProcessors());
23+
String str = "垃圾空间";
24+
for (int i=0;i <30000; i++) {
25+
str = str + i;
26+
}
27+
System.out.println("[2]获取最大可用内存空间:" + run.maxMemory() + "字节,默认的配置为本机系统内存的4分之1");
28+
System.out.println("[2]获取可用内存空间:" + run.totalMemory() + "字节,默认的配置为本机系统内存的64分之1");
29+
System.out.println("[2]获取空余内存空间:" + run.freeMemory() + "字节");
30+
System.out.println("availableProcessors方法可以获取本机的CPU内核数:" + run.availableProcessors());
31+
Thread.sleep(2000);
1132
run.gc();//手工调用垃圾回收
12-
System.gc();
33+
System.gc();//System.gc内部调用的就是run.gc()
1334

14-
RunntimeTest sdf = new RunntimeTest();
15-
try {
16-
sdf.finalize();
17-
} catch (Throwable e) {
18-
e.printStackTrace();
19-
}
35+
System.out.println("[3]获取最大可用内存空间:" + run.maxMemory() + "字节,默认的配置为本机系统内存的4分之1");
36+
System.out.println("[3]获取可用内存空间:" + run.totalMemory() + "字节,默认的配置为本机系统内存的64分之1");
37+
System.out.println("[3]获取空余内存空间:" + run.freeMemory() + "字节");
38+
System.out.println("availableProcessors方法可以获取本机的CPU内核数:" + run.availableProcessors());
39+
40+
// RunntimeTest sdf = new RunntimeTest();
41+
// try {
42+
// sdf.finalize();
43+
// } catch (Throwable e) {
44+
// e.printStackTrace();
45+
// }
2046

2147
}
2248

2349
@Override
2450
protected void finalize() throws Throwable {
25-
System.out.println("finalize方法会在JAVA进行垃圾回收前,被自动调用" );
51+
/**
52+
* 但是从JDK1.9开始,这一操作已经不建议使用了,而对于对象回收释放.从JDK
53+
* 或者使用java.lang.ref.Cleaner类进行回收(Cleaner也支持有AutoCloseable处理).
54+
*/
55+
System.out.println("finalize方法会在JAVA进行垃圾回收前,被自动调用,这个方法抛出的异常类型为Throwable,但是这个类即使抛出异常了,也不影响后面代码的执行" );
56+
throw new Exception("我不影响后面代码的继续运行,因为我这个类马上就死了");
2657
}
2758
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.yale.test.run;
2+
3+
public class SystemTest {
4+
5+
public static void main(String[] args) {
6+
//System.arraycopy(src, srcPos, dest, destPos, length);数组复制
7+
System.out.println(System.currentTimeMillis());
8+
}
9+
}
199 KB
Loading

0 commit comments

Comments
 (0)