【问题标题】:FTP - Using Spring Integration task-scheduler process stops after certain periodFTP - 使用 Spring Integration 任务调度程序进程在一段时间后停止
【发布时间】:2016-06-17 07:39:07
【问题描述】:

当尝试在 Unix 机器上单独启动 jar 时,任务计划的线程在一段时间后没有监听,但它在 Windows 机器上工作正常。即使应用程序在启动时在 linux 中工作,但有时它不是工作。请让我知道有什么办法可以避免这个问题。

@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);
}

【问题讨论】:

    标签: spring-integration spring-integration-sftp


    【解决方案1】:
    1. 没有理由让一个轮询器紧跟在另一个轮询器之后。我的意思是你不需要那个QueueChannel

    2. callWork(payload); 代码的神奇之处真的很有趣。是不是有什么东西堵了很久?即使这看起来像void(没有返回等待的东西),但你可能有一些线程饥饿代码,它从默认的TaskScheduler(默认为10)窃取了所有线程。

    看起来这与您的另一个问题完全相关Spring Integration ftp Thread process

    【讨论】:

    • 谢谢阿特姆!!此问题已解决,因为 Unix 中的防火墙阻止了该端口,我已从活动端口修改为被动端口,并且它使用链接 - stackoverflow.com/questions/26632577/… 工作。感谢 Artem 和上述链接。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多