You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2008/08/30 11:49:05 UTC

svn commit: r690486 - /maven/site/trunk/src/site/apt/plugin-developers/common-bugs.apt

Author: bentmann
Date: Sat Aug 30 02:49:04 2008
New Revision: 690486

URL: http://svn.apache.org/viewvc?rev=690486&view=rev
Log:
o Pointed out the pitfall with shutdown hooks that Milos once had mentioned

Modified:
    maven/site/trunk/src/site/apt/plugin-developers/common-bugs.apt

Modified: maven/site/trunk/src/site/apt/plugin-developers/common-bugs.apt
URL: http://svn.apache.org/viewvc/maven/site/trunk/src/site/apt/plugin-developers/common-bugs.apt?rev=690486&r1=690485&r2=690486&view=diff
==============================================================================
--- maven/site/trunk/src/site/apt/plugin-developers/common-bugs.apt (original)
+++ maven/site/trunk/src/site/apt/plugin-developers/common-bugs.apt Sat Aug 30 02:49:04 2008
@@ -44,6 +44,8 @@
 
   * {{{Using_System_Properties}Using System Properties}}
 
+  * {{{Using_Shutdown_Hooks}Using Shutdown Hooks}}
+
   * {{{Resolving_Relative_Paths}Resolving Relative Paths}}
 
   * {{{Determining_the_Output_Directory_for_a_Site_Report}Determining the Output Directory for a Site Report}}
@@ -277,6 +279,34 @@
   execution properties. These can be obtained from
   <<<{{{http://maven.apache.org/ref/current/maven-core/apidocs/org/apache/maven/execution/MavenSession.html#getExecutionProperties()}MavenSession.getExecutionProperties()}}>>>.
 
+* {Using Shutdown Hooks}
+
+  People occasionally employ shutdown hooks to perform cleanup tasks, e.g. to delete temporary files as shown in the
+  example below:
+
++---
+public MyMojo extends AbstractMojo
+{
+    public void execute()
+    {
+        File tempFile = File.createTempFile( "temp", null );
+        /*
+         * FIXME: This assumes the JVM terminates soon after
+         * the Maven build has finished.
+         */
+        tempFile.deleteOnExit();
+    }
+}
++---
+
+  The problem is that the JVM executing Maven can be running much longer than the actual Maven build. Of course, this
+  does not apply to the standalone invocation of Maven from the command line. However, it affects the embedded usage of
+  Maven in IDEs or CI servers. In those cases, the cleanup tasks will be deferred, too. If the JVM is then executing a
+  bunch of other Maven builds, many such cleanup tasks can sum up, eating up resources of the JVM.
+
+  For this reason, plugin developers should avoid usage of shutdown hooks and rather use <<<try>>>/<<<finally>>> blocks
+  to perform cleanup as soon as the resources are no longer needed.
+
 * {Resolving Relative Paths}
 
   It is common practice for users of Maven to specify relative paths in the POM, not to mention that the Super POM does