public static CloseWatcher register(Object o,Closeable closeable,boolean stackTrace){
  ReferenceQueue<Object> q=queue;
  if (q == null) {
    q=new ReferenceQueue<Object>();
    queue=q;
  }
  CloseWatcher cw=new CloseWatcher(o,q,closeable);
  if (stackTrace) {
    Exception e=new Exception("Open Stack Trace");
    StringWriter s=new StringWriter();
    e.printStackTrace(new PrintWriter(s));
    cw.openStackTrace=s.toString();
  }
  if (refs == null) {
    refs=createSet();
  }
  refs.add(cw);
  return cw;
}

public static CloseWatcher register ( Object o , Closeable closeable , boolean stackTrace ) { ReferenceQueue < Object > q = queue ; if ( q == null ) { q = new ReferenceQueue < Object > ( ) ; queue = q ; } CloseWatcher cw = new CloseWatcher ( o , q , closeable ) ; if ( stackTrace ) { Exception e = new Exception ( "Open Stack Trace" ) ; StringWriter s = new StringWriter ( ) ; e . printStackTrace ( new PrintWriter ( s ) ) ; cw . openStackTrace = s . toString ( ) ; } if ( refs == null ) { refs = createSet ( ) ; } refs . add ( cw ) ; return cw ; }
register an object . before calling this method , pollunclosed ( ) should be called in a loop to remove old references .
