/** * Same as {@link File#createTempFile(String, String, File)} except that * the newly-created file will be automatically deleted once the * returned <code>File</code> object has been gc'ed. * * @param prefix The prefix string to be used in generating the file's * name; must be at least three characters long * @param suffix The suffix string to be used in generating the file's * name; may be <code>null</code>, in which case the * suffix <code>".tmp"</code> will be used * @param directory The directory in which the file is to be created, or * <code>null</code> if the default temporary-file * directory is to be used * @return the newly-created empty file * @throws IOException If a file could not be created */ public File createTransientFile(String prefix, String suffix, File directory) throws IOException { File f = File.createTempFile(prefix, suffix, directory); trackedRefs.add(new MoribundFileReference(f, phantomRefQueue)); return f; }
/** * Actually shuts factory down removing all temp files. This happens when * VM shutdown hook works or when explicitly requested. * Shutdown hook is removed. */ private synchronized void doShutdown() { // synchronize on the list before iterating over it in order // to avoid ConcurrentModificationException (JCR-549) // @see java.lang.util.Collections.synchronizedList(java.util.List) synchronized(trackedRefs) { for (Iterator<MoribundFileReference> it = trackedRefs.iterator(); it.hasNext();) { it.next().delete(); } } if (shutdownHook != null) { try { Runtime.getRuntime().removeShutdownHook(shutdownHook); } catch (IllegalStateException e) { // can't unregister shutdownhook because // jvm shutdown sequence has already begun, // silently ignore... } shutdownHook = null; } reaper.stopWorking(); }
/** * Actually shuts factory down removing all temp files. This happens when * VM shutdown hook works or when explicitly requested. * Shutdown hook is removed. */ private synchronized void doShutdown() { // synchronize on the list before iterating over it in order // to avoid ConcurrentModificationException (JCR-549) // @see java.lang.util.Collections.synchronizedList(java.util.List) synchronized(trackedRefs) { for (Iterator<MoribundFileReference> it = trackedRefs.iterator(); it.hasNext();) { it.next().delete(); } } if (shutdownHook != null) { try { Runtime.getRuntime().removeShutdownHook(shutdownHook); } catch (IllegalStateException e) { // can't unregister shutdownhook because // jvm shutdown sequence has already begun, // silently ignore... } shutdownHook = null; } reaper.stopWorking(); }
/** * Run the reaper thread that will delete files as their associated * marker objects are reclaimed by the garbage collector. */ public void run() { while (!stopping) { MoribundFileReference fileRef = null; try { // wait until a MoribundFileReference is ready for deletion fileRef = (MoribundFileReference) phantomRefQueue.remove(); } catch (InterruptedException e) { if (stopping) { break; } } catch (Exception e) { // silently ignore... continue; } // delete target fileRef.delete(); fileRef.clear(); trackedRefs.remove(fileRef); } }
/** * Run the reaper thread that will delete files as their associated * marker objects are reclaimed by the garbage collector. */ public void run() { while (!stopping) { MoribundFileReference fileRef = null; try { // wait until a MoribundFileReference is ready for deletion fileRef = (MoribundFileReference) phantomRefQueue.remove(); } catch (InterruptedException e) { if (stopping) { break; } } catch (Exception e) { // silently ignore... continue; } // delete target fileRef.delete(); fileRef.clear(); trackedRefs.remove(fileRef); } }
/** * Actually shuts factory down removing all temp files. This happens when * VM shutdown hook works or when explicitly requested. * Shutdown hook is removed. */ private synchronized void doShutdown() { // synchronize on the list before iterating over it in order // to avoid ConcurrentModificationException (JCR-549) // @see java.lang.util.Collections.synchronizedList(java.util.List) synchronized(trackedRefs) { for (Iterator<MoribundFileReference> it = trackedRefs.iterator(); it.hasNext();) { it.next().delete(); } } if (shutdownHook != null) { try { Runtime.getRuntime().removeShutdownHook(shutdownHook); } catch (IllegalStateException e) { // can't unregister shutdownhook because // jvm shutdown sequence has already begun, // silently ignore... } shutdownHook = null; } reaper.stopWorking(); }
/** * Run the reaper thread that will delete files as their associated * marker objects are reclaimed by the garbage collector. */ public void run() { while (!stopping) { MoribundFileReference fileRef = null; try { // wait until a MoribundFileReference is ready for deletion fileRef = (MoribundFileReference) phantomRefQueue.remove(); } catch (InterruptedException e) { if (stopping) { break; } } catch (Exception e) { // silently ignore... continue; } // delete target fileRef.delete(); fileRef.clear(); trackedRefs.remove(fileRef); } }
/** * Run the reaper thread that will delete files as their associated * marker objects are reclaimed by the garbage collector. */ public void run() { while (true) { MoribundFileReference fileRef = null; try { // wait until a MoribundFileReference is ready for deletion fileRef = (MoribundFileReference) phantomRefQueue.remove(); } catch (Exception e) { // silently ignore... continue; } // delete target fileRef.delete(); fileRef.clear(); trackedRefs.remove(fileRef); } } }
/** * Same as {@link File#createTempFile(String, String, File)} except that * the newly-created file will be automatically deleted once the * returned <code>File</code> object has been gc'ed. * * @param prefix The prefix string to be used in generating the file's * name; must be at least three characters long * @param suffix The suffix string to be used in generating the file's * name; may be <code>null</code>, in which case the * suffix <code>".tmp"</code> will be used * @param directory The directory in which the file is to be created, or * <code>null</code> if the default temporary-file * directory is to be used * @return the newly-created empty file * @throws IOException If a file could not be created */ public File createTransientFile(String prefix, String suffix, File directory) throws IOException { File f = File.createTempFile(prefix, suffix, directory); trackedRefs.add(new MoribundFileReference(f, phantomRefQueue)); return f; }
/** * Same as {@link File#createTempFile(String, String, File)} except that * the newly-created file will be automatically deleted once the * returned <code>File</code> object has been gc'ed. * * @param prefix The prefix string to be used in generating the file's * name; must be at least three characters long * @param suffix The suffix string to be used in generating the file's * name; may be <code>null</code>, in which case the * suffix <code>".tmp"</code> will be used * @param directory The directory in which the file is to be created, or * <code>null</code> if the default temporary-file * directory is to be used * @return the newly-created empty file * @throws IOException If a file could not be created */ public File createTransientFile(String prefix, String suffix, File directory) throws IOException { File f = File.createTempFile(prefix, suffix, directory); trackedRefs.add(new MoribundFileReference(f, phantomRefQueue)); return f; }
/** * Same as {@link File#createTempFile(String, String, File)} except that * the newly-created file will be automatically deleted once the * returned <code>File</code> object has been gc'ed. * * @param prefix The prefix string to be used in generating the file's * name; must be at least three characters long * @param suffix The suffix string to be used in generating the file's * name; may be <code>null</code>, in which case the * suffix <code>".tmp"</code> will be used * @param directory The directory in which the file is to be created, or * <code>null</code> if the default temporary-file * directory is to be used * @return the newly-created empty file * @throws IOException If a file could not be created */ public File createTransientFile(String prefix, String suffix, File directory) throws IOException { File f = File.createTempFile(prefix, suffix, directory); trackedRefs.add(new MoribundFileReference(f, phantomRefQueue)); return f; }
public void run() { // synchronize on the list before iterating over it in order // to avoid ConcurrentModificationException (JCR-549) // @see java.lang.util.Collections.synchronizedList(java.util.List) synchronized(trackedRefs) { for (Iterator it = trackedRefs.iterator(); it.hasNext();) { MoribundFileReference fileRef = (MoribundFileReference) it.next(); fileRef.delete(); } } } });