Search code examples
spring-integrationspring-integration-sftp

FTP - Using Spring Integration task-scheduler process stops after certain period


When trying to start the jar seperately in Unix machine the Thread for task-schedular is not listnening after some time but it is working fine in Windows machine.Even the application is working in linux on startup but going further sometime it is not working.Please let me know Is there any way to avoid the issue.

@Bean
@InboundChannelAdapter(value = "inputChannel", poller = @Poller(fixedDelay = "1000", maxMessagesPerPoll = "1"))
public MessageSource<?> receive() {

    FtpInboundFileSynchronizingMessageSource messageSource = new FtpInboundFileSynchronizingMessageSource(synchronizer());
    File Temp = new File(TEMP_FOLDER);
    messageSource.setLocalDirectory(Temp);
    messageSource.setAutoCreateLocalDirectory(true);
    return messageSource;
}

private AbstractInboundFileSynchronizer<FTPFile> synchronizer() {

    AbstractInboundFileSynchronizer<FTPFile> fileSynchronizer = new FtpInboundFileSynchronizer(sessionFactory());
    fileSynchronizer.setRemoteDirectory(ftpFileLocation);
    fileSynchronizer.setDeleteRemoteFiles(false);
    Pattern pattern = Pattern.compile(".*\\.xml$");
    FtpRegexPatternFileListFilter ftpRegexPatternFileListFilter = new FtpRegexPatternFileListFilter(pattern);
    fileSynchronizer.setFilter(ftpRegexPatternFileListFilter);
    return fileSynchronizer;
}


@Bean(name = "sessionFactory")
public SessionFactory<FTPFile> sessionFactory() {

    DefaultFtpSessionFactory sessionFactory = new DefaultFtpSessionFactory();
    sessionFactory.setHost(ftpHostName);
    sessionFactory.setUsername(ftpUserName);
    sessionFactory.setPassword(ftpPassWord);
    return sessionFactory;
}

@Bean(name = "inputChannel")
public PollableChannel inputChannel() {
    return new QueueChannel();
}

@Bean(name = PollerMetadata.DEFAULT_POLLER)
public PollerMetadata defaultPoller() {

    PollerMetadata pollerMetadata = new PollerMetadata();
    pollerMetadata.setTrigger(new PeriodicTrigger(100));
    return pollerMetadata;
}

@ServiceActivator(inputChannel = "inputChannel")
public void transferredFilesFromFTP(File payload) {
    callWork(payload);
}

Solution

    1. There is no reason to have one poller immediately after another one. I mean you don't need that QueueChannel.

    2. It's really interesting what does that magic callWork(payload); code do. Doesn't it have anything blocking for some long time? Even if that looks like void (without returning something to wait), but you may have there some thread starvation code, which steals all the thread from the default TaskScheduler (10 by default).

    Looks like this is fully related to your another question Spring Integration ftp Thread process