@Ignore @Test public void fetchAndConsume( ) { ReferenceQueue<CachedDataBaseReferenceReader> rq = new ReferenceQueue<CachedDataBaseReferenceReader>(); WeakReference<CachedDataBaseReferenceReader> weakR = new WeakReference<CachedDataBaseReferenceReader>( CachedDataBaseReferenceReader.getCachedReader(),rq); boolean outOfMem = false; ArrayList<int[]> pig = new ArrayList<int[]>( ); for (int size = 10;!outOfMem;size*=10) { try { assertFalse(weakR.isEnqueued()); pig.add(new int[size]); CachedDataBaseReferenceReader w = weakR.get( ); assertTrue(w == CachedDataBaseReferenceReader.getCachedReader()); } catch(OutOfMemoryError error) { assertTrue(weakR.isEnqueued()); assertTrue(weakR.get( ) == null); outOfMem = true; } } pig.clear(); CachedDataBaseReferenceReader dbReader = CachedDataBaseReferenceReader.getCachedReader(); assertTrue(dbReader != null); }
public static CachedDataBaseReferenceReader getCachedReader( ) { CachedDataBaseReferenceReader r = dbReader.get(); if (r != null) { return r; } synchronized(dbReader) { r = dbReader.get(); if (r != null) { return r; } r = new CachedDataBaseReferenceReader(); dbReader = new SoftReference<CachedDataBaseReferenceReader>(r); } return r; }
CachedDataBaseReferenceReader { public static CachedDataBaseReferenceReader getCachedReader( ) { CachedDataBaseReferenceReader r = dbReader.get(); if (r != null) { return r; } synchronized(dbReader) { r = dbReader.get(); if (r != null) { return r; } r = new CachedDataBaseReferenceReader(); dbReader = new SoftReference<CachedDataBaseReferenceReader>(r); } return r; } }
CachedDataBaseReferenceReader { public static CachedDataBaseReferenceReader getCachedReader( ) { CachedDataBaseReferenceReader r = dbReader.get(); if (r != null) { return r; } synchronized(dbReader) { r = dbReader.get(); if (r != null) { return r; } r = new CachedDataBaseReferenceReader(); dbReader = new SoftReference<CachedDataBaseReferenceReader>(r); } return r; } private  CachedDataBaseReferenceReader( ); }
CachedDataBaseReferenceReader { public static CachedDataBaseReferenceReader getCachedReader( ) { CachedDataBaseReferenceReader r = dbReader.get(); if (r != null) { return r; } synchronized(dbReader) { r = dbReader.get(); if (r != null) { return r; } r = new CachedDataBaseReferenceReader(); dbReader = new SoftReference<CachedDataBaseReferenceReader>(r); } return r; } private  CachedDataBaseReferenceReader( ); static CachedDataBaseReferenceReader getCachedReader( ); String getMoleculeDataBaseReference(String molId); String getChEBIName(String chebiId); String getGOTerm(String goId); String getMoleculeDataBaseReference(String db, String id); }
CachedDataBaseReferenceReader { public static CachedDataBaseReferenceReader getCachedReader( ) { CachedDataBaseReferenceReader r = dbReader.get(); if (r != null) { return r; } synchronized(dbReader) { r = dbReader.get(); if (r != null) { return r; } r = new CachedDataBaseReferenceReader(); dbReader = new SoftReference<CachedDataBaseReferenceReader>(r); } return r; } private  CachedDataBaseReferenceReader( ); static CachedDataBaseReferenceReader getCachedReader( ); String getMoleculeDataBaseReference(String molId); String getChEBIName(String chebiId); String getGOTerm(String goId); String getMoleculeDataBaseReference(String db, String id);  }