ReferenceQueue rq = new ReferenceQueue();//创建弱引用队列
String s = new String("3");
WeakReference wr = new WeakReference(s, rq);//创建弱引用
system.gc();
system.out.println(wr.get() == null)
这个结果肯定为false,因为堆中开辟内存存储new String(“3”)这个对象,栈中的引用String s 指向了堆中的对象new String(“3”),所以对象new String(“3”)就不仅仅只被wr这个弱引用所引用,还有String s这个强引用。如果一个对象只被一个弱引用所关联,那么在gc的时候一定会被回收,反过来说,如果一个对象不仅被弱引用引用,还被强引用引用,那么gc肯定是无效的,除非你把强引用置空,s=null,取消s对对象new String("3")**的引用,那么gc的时候才wr才会被回收。
private boolean gone(KeyedWeakReference reference) {
return !retainedKeys.contains(reference.key);
}
private void removeWeaklyReachableReferences() {
// WeakReferences are enqueued as soon as the object to which they point to becomes weakly
// reachable. This is before finalization or garbage collection has actually happened.
KeyedWeakReference ref;
while ((ref = (KeyedWeakReference) queue.poll()) != null) {
retainedKeys.remove(ref.key);
}
}
这里写点抛砖引玉,希望大家能把自己整理的问题及解决方法晾出来,Mark一下,利人利己。
出现问题先搜一下文档上有没有,再看看度娘有没有,再看看论坛有没有。有报错要看日志。下面简单罗列下常见的问题,大多文档上都有提到的。
1、repeated column width is largerthan paper width:
这个看这段话应该是很好理解的。比如做的模板页面宽度只能放
这个问题我实在是为整个 springsource 的员工蒙羞
如果大家使用 spring 控制事务,使用 Open Session In View 模式,
com.mchange.v2.resourcepool.TimeoutException: A client timed out while waiting to acquire a resource from com.mchange.
简单模拟实现数据库连接池
实例1:
package com.bijian.thread;
public class DB {
//private static final int MAX_COUNT = 10;
private static final DB instance = new DB();
private int count = 0;
private i
using System;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
namespace WindowsFormsApplication1
{
Configuring Spring and JTA without full Java EE
http://spring.io/blog/2011/08/15/configuring-spring-and-jta-without-full-java-ee/
Spring doc -Transaction Management
http://docs.spring.io/spri