Skip to content

FileUtils.foreceDelete consumed on Windows-System a lot of system resources #21

Description

@kaumein

The foreceDelete will consume on Windows system a lot of time, if it is called a lot of times for files which are not present on the file system.

The method did the following:
if ( !file.delete() ) {
if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) {
file = file.getCanonicalFile();
System.gc();
}
try {
Thread.sleep( 10 );
return file.delete();
} catch ( InterruptedException ignore ) {
return file.delete();
}
}

I suggest to have a look at the {{commons-io}} variant, which is much simpler and did not do any assumption on the opperation system.

A detailed blog entry can be found on my blog: https://kaffeeumeins.de/interesting-code-org-codehaus-plexus-util-fileutils-forcedeletefile

Activity

  1. khmarbaise commented on Feb 19, 2017

    @khmarbaise
    Member

    The why can be read in the javadoc of the method:

      /**
         * Accommodate Windows bug encountered in both Sun and IBM JDKs.
         * Others possible. If the delete does not work, call System.gc(),
         * wait a little and try again.
         *
         * @param file a file
         * @throws IOException if any
         */
        private static boolean deleteFile( File file )
            throws IOException

    Furthermore you have analysed it so in deepth why not offering a patch and make it better ? Apart from that I have my doubts that this method is causing long running build in Eclipse cause it will not being called. The question is how you are doing full builds in Eclipse? Which Eclipse version do you use? Which Maven version do you use? and of course which M2E version do you use?

  2. michael-o commented on Feb 19, 2017

    @michael-o
    Member

    Is the bug still present these days?

  3. kaumein commented on Feb 19, 2017

    @kaumein
    Author

    I saw that comment, but there are no references to have a look at :(

    As describted in the blog it is in the yuicompressor-plugin which just want to be sure a file does not exists on the filesystem. If some other plugin will use this function in the same way it will also end up in consuming 100% CPU and slows down the build.
    On the other hand, if the plugin does not correctly uses this function it should be fixed in the plugin and the documentation of forceDelete has to be changed.

    @khmarbaise I just want to understand why it is programmed in this way, before changing it to use just file.delete (like commons-io, it looks like tjey have not those mentioned problems) -- changing without any question can produce a lot of trouble in the code which uses this function and in the community.

    @michael-o: the code ist from the latest version 3.0.24

  4. michael-o commented on Feb 19, 2017

    @michael-o
    Member

    @muehlehh I was talking about:

    Accommodate Windows bug encountered in both Sun and IBM JDKs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions