2016-07-08 24 views
0

我有一个这样的类:辛格尔顿与集群

@Singleton 
public class RecoveryWorker { 
    @Schedule(minute = "*/1", hour = "*", persistent = false) 
    public void run() { 
     // heavy db queries ~ 2sec 
     ... 
    } 
    ... 
} 

有哪个有这个单,并与同一个Oracle DB

有时候我有错误的原理2个wildfly实例:

RROR [org.jboss.as.ejb3] (EJB default - 10) JBAS014120: Error invoking timeout for timer: [id=66ed65c4-3a2d-4343-870d-5f7a46a7742c timedObjectId=com.package.Worker auto-timer?:true persistent?:false [email protected]950e6 initialExpiration=null intervalDuration(in milli sec)=0 nextExpiration=Wed Jun 15 00:01:00 CEST 2016 timerState=IN_TIMEOUT info=null: javax.ejb.ConcurrentAccessTimeoutException: JBAS014373: EJB 3.1 PFD2 4.8.5.5.1 concurrent access timeout on [email protected] - could not obtain lock within 5000MILLISECONDS

我想知道这个块是怎么发生的(Oracle有机械阻塞表或其他东西?)在一个时间内在几个实例中运行一个单例的最佳实践是什么?

+0

看看http://stackoverflow.com/questions/27952769/clustered-singleton-using-wildfly和https://docs.jboss.org/author/display/WFLY10/HA+Singleton+Features,如果你正在使用Wildfly 10 –

回答

0

@Singleton只是JVM的单例,不能保证它一次只能在一个实例上运行。

JBAS014120是因为@Singleton合约,您的计时器是每分钟。在你的情况下,我想有时候“重型数据库查询”可以运行更长时间,而另一个单例将会启动,因为你没有将锁权限设置为READ,每个对单例的调用都将被合同阻止。

如果你需要一个集群单身人士,你应该检查快速入门。 我已经写了cluster-ha-singleton,这是你的用例的例子。 https://github.com/wildfly/quickstart 它将选择一个节点并仅在其中一个群集节点上启动调度,如果节点崩溃,它将进行故障转移。