Code example for PhantomReference

0
	public synchronized Resource getResource(Object key) {
		if (shutdown)
			throw new IllegalStateException();
		Resource res = new ResourceImpl(key);
		Reference<?> ref =
			new PhantomReference<Object>(key, queue);
		refs.put(ref, res);
		return res;
	} 
	 
	 
	 
	private static class ResourceImpl implements Resource { 
		Reference<?> keyRef;
		boolean needsRelease = false;
		 
		ResourceImpl(Object key) {
			keyRef =new WeakReference<Object>(key);
			needsRelease = true;
		}