Source Code Cross Referenced for FileCleaner.java in  » Library » apache-common-IO » org » apache » commons » io » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » apache common IO » org.apache.commons.io 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.commons.io;
018:
019:        import java.io.File;
020:
021:        /**
022:         * Keeps track of files awaiting deletion, and deletes them when an associated
023:         * marker object is reclaimed by the garbage collector.
024:         * <p>
025:         * This utility creates a background thread to handle file deletion.
026:         * Each file to be deleted is registered with a handler object.
027:         * When the handler object is garbage collected, the file is deleted.
028:         * <p>
029:         * In an environment with multiple class loaders (a servlet container, for
030:         * example), you should consider stopping the background thread if it is no
031:         * longer needed. This is done by invoking the method
032:         * {@link #exitWhenFinished}, typically in
033:         * {@link javax.servlet.ServletContextListener#contextDestroyed} or similar.
034:         *
035:         * @author Noel Bergman
036:         * @author Martin Cooper
037:         * @version $Id: FileCleaner.java 551002 2007-06-27 01:33:05Z jochen $
038:         */
039:        public class FileCleaner {
040:            /**
041:             * The instance to use for the deprecated, static methods.
042:             */
043:            static final FileCleaningTracker theInstance = new FileCleaningTracker();
044:
045:            //-----------------------------------------------------------------------
046:            /**
047:             * Track the specified file, using the provided marker, deleting the file
048:             * when the marker instance is garbage collected.
049:             * The {@link FileDeleteStrategy#NORMAL normal} deletion strategy will be used.
050:             *
051:             * @param file  the file to be tracked, not null
052:             * @param marker  the marker object used to track the file, not null
053:             * @throws NullPointerException if the file is null
054:             */
055:            public static void track(File file, Object marker) {
056:                theInstance.track(file, marker);
057:            }
058:
059:            /**
060:             * Track the specified file, using the provided marker, deleting the file
061:             * when the marker instance is garbage collected.
062:             * The speified deletion strategy is used.
063:             *
064:             * @param file  the file to be tracked, not null
065:             * @param marker  the marker object used to track the file, not null
066:             * @param deleteStrategy  the strategy to delete the file, null means normal
067:             * @throws NullPointerException if the file is null
068:             */
069:            public static void track(File file, Object marker,
070:                    FileDeleteStrategy deleteStrategy) {
071:                theInstance.track(file, marker, deleteStrategy);
072:            }
073:
074:            /**
075:             * Track the specified file, using the provided marker, deleting the file
076:             * when the marker instance is garbage collected.
077:             * The {@link FileDeleteStrategy#NORMAL normal} deletion strategy will be used.
078:             *
079:             * @param path  the full path to the file to be tracked, not null
080:             * @param marker  the marker object used to track the file, not null
081:             * @throws NullPointerException if the path is null
082:             */
083:            public static void track(String path, Object marker) {
084:                theInstance.track(path, marker);
085:            }
086:
087:            /**
088:             * Track the specified file, using the provided marker, deleting the file
089:             * when the marker instance is garbage collected.
090:             * The speified deletion strategy is used.
091:             *
092:             * @param path  the full path to the file to be tracked, not null
093:             * @param marker  the marker object used to track the file, not null
094:             * @param deleteStrategy  the strategy to delete the file, null means normal
095:             * @throws NullPointerException if the path is null
096:             */
097:            public static void track(String path, Object marker,
098:                    FileDeleteStrategy deleteStrategy) {
099:                theInstance.track(path, marker, deleteStrategy);
100:            }
101:
102:            //-----------------------------------------------------------------------
103:            /**
104:             * Retrieve the number of files currently being tracked, and therefore
105:             * awaiting deletion.
106:             *
107:             * @return the number of files being tracked
108:             */
109:            public static int getTrackCount() {
110:                return theInstance.getTrackCount();
111:            }
112:
113:            /**
114:             * Call this method to cause the file cleaner thread to terminate when
115:             * there are no more objects being tracked for deletion.
116:             * <p>
117:             * In a simple environment, you don't need this method as the file cleaner
118:             * thread will simply exit when the JVM exits. In a more complex environment,
119:             * with multiple class loaders (such as an application server), you should be
120:             * aware that the file cleaner thread will continue running even if the class
121:             * loader it was started from terminates. This can consitute a memory leak.
122:             * <p>
123:             * For example, suppose that you have developed a web application, which
124:             * contains the commons-io jar file in your WEB-INF/lib directory. In other
125:             * words, the FileCleaner class is loaded through the class loader of your
126:             * web application. If the web application is terminated, but the servlet
127:             * container is still running, then the file cleaner thread will still exist,
128:             * posing a memory leak.
129:             * <p>
130:             * This method allows the thread to be terminated. Simply call this method
131:             * in the resource cleanup code, such as {@link javax.servlet.ServletContextListener#contextDestroyed}.
132:             * One called, no new objects can be tracked by the file cleaner.
133:             */
134:            public static synchronized void exitWhenFinished() {
135:                theInstance.exitWhenFinished();
136:            }
137:
138:            /**
139:             * Returns the singleton instance, which is used by the deprecated, static methods.
140:             * This is mainly useful for code, which wants to support the new
141:             * {@link FileCleaningTracker} class while maintain compatibility with the
142:             * deprecated {@link FileCleaner}.
143:             */
144:            public static FileCleaningTracker getInstance() {
145:                return theInstance;
146:            }
147:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.