首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring集成2与Quartz调度器

Spring集成2与Quartz调度器
EN

Stack Overflow用户
提问于 2012-01-17 23:25:04
回答 2查看 2.1K关注 0票数 3

我是Spring Integration的新手。

我已经配置了一个Spring文件入站通道适配器,例如

代码语言:javascript
复制
<file:inbound-channel-adapter channel="channel1" directory="${location}" prevent-duplicates="true" filename-pattern="*.csv">
        <si:poller>
            <si:interval-trigger interval="1000"/>
        </si:poller>
</file:inbound-channel-adapter>

<si:service-activator input-channel="channel1" output-channel="channel2" ref="filenameGenerator" method="generate"/>

现在,它工作得很好。但这需要部署在集群环境中。我希望确保集群中的多个实例不会尝试读取相同的文件。那么,这在这样的环境下会起作用吗?

如果没有,我可以像这样使用Quartz调度器吗:

代码语言:javascript
复制
    <file:inbound-channel-adapter channel="channel1" directory="${location}" prevent-duplicates="true" filename-pattern="*.csv">
             <si:poller task-executor="taskExecutor" fixed-rate="1000"/>
    </file:inbound-channel-adapter>

    <si:service-activator input-channel="channel1" output-channel="channel2" ref="filenameGenerator" method="generate"/>

    <bean id="taskExecutor" class="org.springframework.scheduling.quartz.SimpleThreadPoolTaskExecutor">
        <property name="threadCount" value="20"/>
        <property name="threadNamePrefix" value="consumer"/>
    </bean>

这能解决我的问题吗??或者我必须使用Transaction?

我希望问题是清楚的。

谢谢,阿迪

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-01-18 00:45:31

当多个进程正在从同一目录读取数据时,可能需要锁定文件以防止它们被并发拾取。为此,您可以使用FileLocker

查看有关文件锁定器here的文档。看起来你可以这样做:

代码语言:javascript
复制
<file:inbound-channel-adapter ... >
  <file:nio-locker/>
</file:inbound-channel-adapter>

当多个进程正在从同一目录读取数据时,可能需要锁定文件以防止它们被并发拾取。为此,您可以使用FileLocker

票数 2
EN

Stack Overflow用户

发布于 2014-08-02 06:18:43

要确保quartz调度的作业在群集中只执行一次,请配置一个持久的群集quartz作业调度。以下是Quartz 1.6.6的示例配置:

代码语言:javascript
复制
  <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <!--        Set whether any jobs defined on this SchedulerFactoryBean should
            overwrite existing job definitions.
      --> 
    <property name="overwriteExistingJobs" value="true" /> 
  <property name="dataSource" ref="myTransactionalDataSource" /> 

<!-- nonTransactionalDataSource is only necessary with clustered Quartz with an XA DataSource.  
  --> 
  <property name="nonTransactionalDataSource" ref="myNonTransactionalDataSource" /> 

 <property name="quartzProperties">
  <props>
  <prop key="org.quartz.jobStore.selectWithLockSQL">SELECT * FROM {0}LOCKS WITH(UPDLOCK,HOLDLOCK) WHERE LOCK_NAME = ?</prop> 
  <!-- 
    Run in cluster.  Quartz ensures persisted jobs are executed once within the 
                      cluster
  --> 
  <prop key="org.quartz.jobStore.isClustered">true</prop> 

 <!--   Each node in the cluster must have a unique instance id.  
  --> 
  <prop key="org.quartz.scheduler.instanceId">AUTO</prop> 
 <!--   Default clusterCheckinInterval is 15000 
  --> 
  <!--  <prop key="org.quartz.jobStore.clusterCheckinInterval">20000</prop> 
  --> 
 </props>
  </property>
  <property name="transactionManager" ref="transactionManager" /> 
- <!-- 
        In Quartz 1.6.6, Quartz's ThreadPool interface is used when firing job triggers, 
        in org.quartz.core.QuartzSchedulerThread. 
        Quartz 1.x still starts some unmanaged threads, notably org.quartz.impl.jdbcjobstore.JobStoreSupport's
        ClusterManager which is used when clustered=true. Quartz 2.0 should correct this problem.       
  --> 
  <property name="taskExecutor" ref="myTaskExecutor" /> 
  </bean>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8897183

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档