ulimit issue with spring boot and Files.nio

161 Views Asked by At

We are using spring batch and integration in one of our project

We used spring integration for polling and monitoring a directory; when a file comes into the directory, we log and move to a different directory

This is how we are monitoring

 @Bean
    @InboundChannelAdapter(value = "fileChannel", poller = @Poller(fixedDelay = "1000"))
    public MessageSource<File> fileReadingMessageSource() {
        FileReadingMessageSource sourceReader= new FileReadingMessageSource();
        sourceReader.setDirectory(new File(INPUT_DIR));
        sourceReader.setFilter(new SimplePatternFileListFilter(FILE_PATTERN));
        return sourceReader;
    }

Once a file been polled, we are moving a diff temp directory using the below function..we are using java.nio.file.File

Files.move(source, destination, REPLACE_EXISTING);

In the unix box after file been copied to copied even after our processing we still see IO file reference ..This is causing too many files open issue on the container

The way I verified IO connection is still there by using below command:

lsof -u <userid> | grep <file_name>

Currently, we are restarting the spring boot app as a work around to fix the issue. Any thoughts/suggestions to fix this issue?

1

There are 1 best solutions below

0
Artem Bilan On

Apparently you have some logic downstream of that fileChannel which opens a InputStream for the file to read its content. And you just don't close that stream after reading. The Files.move() has nothing to do with opening/closing file resources. See its JavaDocs.