Bug 62012 - Disposing POI temporary files in multithreaded system
Summary: Disposing POI temporary files in multithreaded system
Status: RESOLVED WORKSFORME
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.17-FINAL
Hardware: Other Linux
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-01-18 06:02 UTC by cohen.yaniv.il
Modified: 2018-04-05 19:28 UTC (History)
2 users (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description cohen.yaniv.il 2018-01-18 06:02:37 UTC
Hi,
I'm using POI SXSSFWorkbook for creating XLSX files in multithreaded system.
Since i read that there are issues with disposing the temporary files in when using the DefaultTempFileCreationStrategy (with poifiles directory), i created each thread is own temporary directory:

private TempFileCreationStrategy createTempFileCreationStrategy(File poiTempFileDirectory) {
        return new TempFileCreationStrategy() {
            @Override
            public File createTempFile(String prefix, String suffix) throws IOException {
                if (!poiTempFileDirectory.exists()) {
                    poiTempFileDirectory.mkdir();
                }
                File newFile = File.createTempFile(prefix, suffix, poiTempFileDirectory);
                return newFile;
            }

            @Override
            public File createTempDirectory(String prefix) throws IOException {
                return null;
            }
        };


This is the code while finishing handling the SXSSFWorkbook object:

       // Write the Stream and close it
        workBook.write(outputStream);

            outputStream.close();

        } catch (FileNotFoundException e) {
            throw e;
        } catch (IOException e) {
            throw e;
        } catch (Exception e) {
            throw e;
        } finally {
            //Close the workBook
            workBook.close();
            //deleting the temporary files
            workBook.dispose();
        }

But still, from time to time, i'm getting an exception during the dispose. One thread is throwing exception while trying to delete the temporary files of another thread and the message is:
"dc319a2c-a663-4cb7-9f13-f7e8cc14c186/poi-sxssf-sheet-xml6608967316211277648.gz (No such file or directory)" 

Thanks in advanced
Comment 1 Dominik Stadler 2018-01-18 06:53:24 UTC
Can you post the full stacktrace to let us see where exactly this happens?
Comment 2 cohen.yaniv.il 2018-01-21 11:24:47 UTC
Hi Dominik,
I'm getting this exception very rarely, (around every 1,000 usings), i'm trying to get the stack trace. The moment i'll get it, i'll send it to you.

Thanks
Yaniv
Comment 3 PJ Fanning 2018-01-22 22:36:06 UTC
Is it possible that some external process is reaping files from the temp directory?
In my applications, I try to use an explicit java.io.tmpdir to avoid using /tmp. I have multi-threaded apps using POI and have not hit issues with temp files being deleted while they are still in use.
Comment 4 Dominik Stadler 2018-04-05 19:01:27 UTC
Can you post your complete TempFileCreationStrategy? The code you showed does not look complete. I would like to try to reproduce or at least add a similar test to Apache POI.
Comment 5 Dominik Stadler 2018-04-05 19:28:49 UTC
I tried to reproduce this with a simple threaded TempFileCreationStrategy, but I could not produce any problem or leftover file with it, thus I am closing this as WORKSFORME for now, please reopen when you can provide some more information that can allow to reproduce this.