public class PhantomReference extends Reference {
public T get() {
return null;
}
public PhantomReference(T referent, ReferenceQueue super T> q) {
super(referent, q);
}
}
代码示例:
@Slf4j
public class RefernceTest {
public static void main(String[] args) {
Object obj = new Object();
ReferenceQueue referenceQueue = new ReferenceQueue<>();
PhantomReference phantomReference = new PhantomReference<>(obj,referenceQueue);
log.info("{}","***************GC回收前***************");
log.info("{}",obj);
log.info("{}",phantomReference.get());
log.info("{}",referenceQueue.poll());
log.info("{}","***************启动GC***************");
obj = null;
System.gc();
try {
Thread.sleep(500); //确保GC都执行完了
} catch (InterruptedException e) {
e.printStackTrace();
}
log.info("{}",obj);
log.info("{}",phantomReference.get());
log.info("{}",referenceQueue.poll());
}
}
执行结果:
09:59:57.128 [main] INFO com.example.demo.thread.RefernceTest - ***************GC回收前***************
09:59:57.132 [main] INFO com.example.demo.thread.RefernceTest - java.lang.Object@1996cd68
09:59:57.132 [main] INFO com.example.demo.thread.RefernceTest - null
09:59:57.133 [main] INFO com.example.demo.thread.RefernceTest - null
09:59:57.133 [main] INFO com.example.demo.thread.RefernceTest - ***************启动GC***************
09:59:57.647 [main] INFO com.example.demo.thread.RefernceTest - null
09:59:57.647 [main] INFO com.example.demo.thread.RefernceTest - null
09:59:57.647 [main] INFO com.example.demo.thread.RefernceTest - java.lang.ref.PhantomReference@3339ad8e
/*
*处理例外
*/
--例外简介
--处理例外-传递例外
declare
v_ename emp.ename%TYPE;
begin
SELECT ename INTO v_ename FROM emp
where empno=&no;
dbms_output.put_line('雇员名:'||v_ename);
exceptio
import java.util.ArrayList;
import java.util.List;
public class KickOutBadGuys {
/**
* 题目:13个坏人和13个好人站成一圈,数到7就从圈里面踢出一个来,要求把所有坏人都给踢出来,所有好人都留在圈里。请找出初始时坏人站的位置。
* Maybe you can find out
Redis.conf配置文件及相关项说明
# Redis configuration file example
# Note on units: when memory size is needed, it is possible to specifiy
# it in the usual form of 1k 5GB 4M and so forth:
#
public static String convertInputStreamToString(InputStream is) {
StringBuilder result = new StringBuilder();
if (is != null)
try {
InputStreamReader inputReader = new InputStreamRead
原文:
http://www.sitepoint.com/3-new-javascript-apis-may-want-follow/?utm_source=html5weekly&utm_medium=email
本文中,介绍3个仍然处于草稿阶段,但应该值得关注的Javascript API.
1) Web Alarm API
&