File tree 2 files changed +19
-2
lines changed
src/main/java/com/algorithm/study/demo
2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change 16
16
- [ IO模型有哪些,讲讲你理解的nio ,他和bio,aio的区别是啥,谈谈reactor模型。] ( https://www.cnblogs.com/javalyy/p/8882066.html )
17
17
- [ 反射的原理,反射创建类实例的三种方式是什么。] ( http://blog.51cto.com/4247649/2109128 )
18
18
- 反射中,Class.forName和ClassLoader区别 。
19
+ - [ java动态代理实现与原理详细分析] ( https://www.cnblogs.com/gonjan-blog/p/6685611.html )
19
20
- [ 描述动态代理的几种实现方式,分别说出相应的优缺点。] ( https://blog.csdn.net/wufaliang003/article/details/79305688/ )
20
21
- [ 动态代理与cglib实现的区别。] ( https://www.cnblogs.com/ygj0930/p/6542259.html )
21
22
- 为什么CGlib方式可以对接口实现代理。
Original file line number Diff line number Diff line change 1
1
package com .algorithm .study .demo ;
2
2
3
+ import java .lang .ref .PhantomReference ;
4
+ import java .lang .ref .Reference ;
5
+ import java .lang .ref .ReferenceQueue ;
6
+
3
7
/**
4
8
* @Author: liuxun
5
9
* @CreateDate: 2019/1/2 上午11:29
6
10
* @Version: 1.0
7
11
*/
8
12
public class MainTest {
9
13
public static void main (String [] args ) {
10
- while (true ){
11
-
14
+ Object counter = new Object ();
15
+ ReferenceQueue refQueue = new ReferenceQueue <>();
16
+ PhantomReference <Object > p = new PhantomReference <>(counter , refQueue );
17
+ counter = null ;
18
+ System .gc ();
19
+ try {
20
+ // Remove 是一个阻塞方法,可以指定 timeout,或者选择一直阻塞
21
+ Reference <Object > ref = refQueue .remove (1000L );
22
+ if (ref != null ) {
23
+ System .out .println ("counter gc" );
24
+ }
25
+ } catch (InterruptedException e ) {
26
+ // Handle it
12
27
}
28
+
13
29
}
14
30
}
You can’t perform that action at this time.
0 commit comments