2012-12-18 63 views
1

我已经创建了EJB 3 Timer,并将其部署到weblogic群集中。 createTimer参数是createTimer(1000,20000,null); 这应该每20秒创建一个循环计时器。但计时器始终每30秒创建一次。我甚至将intervalDuration更改为40和50秒,但超时方法始终每30秒触发一次。ejb轮询器每隔30秒触发一次

下面是从WEBLOGIC_TIMERS表中的条目 1 @@ OSBNode2_1355845459844(BLOB)1355846770914 1000 TimerearTimerTest.jarTimerTest OSBDomain OSBCluster

下面是从ACTIVE表中的条目 timer.1 @@ OSBNode2_1355843156331 -96726833478167425/OSBNode2 OSBDomain OSBCluster 18-DEC-12 service.TimerMaster 8866906753834651127/OSBNode1 OSBDomain OSBCluster 18-DEC-12 service.SINGLETON_MASTER 8866906753834651127/OSBNode1 OSBDomain OSBCluster 18-DEC-12

谁能帮我调查为什么总是计时器trigge rs每隔30秒而不是我的intervalDuration值?

下面是EJB ----- >>

package com.timertest; 
import java.util.*; 
import javax.annotation.Resource; 
import javax.ejb.*; 

@Stateless(mappedName = "TimerTest") 
public class TimerTest implements TimerTestRemote 
{ 
    @Resource 
    private SessionContext ctx; 

    @Override 
    public void createMyTimer() 
    throws EJBException 
    { 
     ctx.getTimerService().createTimer(1000, 20000, null); 
    } 

    @Timeout 
    public void timeout(Timer timer) 
    { 
     System.out.println("-> Timed Out ..."+ new Date()); 

    } 
} 


Below is the and weblogic descripor-------->> 
    <?xml version="1.0" encoding="UTF-8"?> 
<wls:weblogic-ejb-jar 
    xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-ejb-jar" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd http://xmlns.oracle.com/weblogic/weblogic-ejb-jar http://xmlns.oracle.com/weblogic/weblogic-ejb-jar/1.2/weblogic-ejb-jar.xsd"> 
    <wls:weblogic-enterprise-bean> 
     <wls:ejb-name>TimerTest</wls:ejb-name> 
     <wls:stateless-session-descriptor> 

      <wls:stateless-clustering> 
       <wls:home-is-clusterable>true</wls:home-is-clusterable> 
       <wls:home-load-algorithm>round-robin</wls:home-load-algorithm> 
       <wls:stateless-bean-is-clusterable>true</wls:stateless-bean-is-clusterable> 
       <wls:stateless-bean-load-algorithm>round-robin 
       </wls:stateless-bean-load-algorithm> 
      </wls:stateless-clustering> 
      <wls:business-interface-jndi-name-map> 
       <wls:business-remote>TimerTestRemote</wls:business-remote> 
       <wls:jndi-name>TimerTest</wls:jndi-name> 
      </wls:business-interface-jndi-name-map> 
     </wls:stateless-session-descriptor> 
     <wls:enable-call-by-reference>false</wls:enable-call-by-reference> 
     <wls:jndi-name>TimerTest</wls:jndi-name> 
    </wls:weblogic-enterprise-bean> 
    <wls:timer-implementation>Clustered</wls:timer-implementation> 
</wls:weblogic-ejb-jar> 

在此先感谢

回答

0

这可能不是直接的答案,但可能有助于避免这种情况。


定时器默认是持久的,所以你必须在开始新的定时器之前取消先前的定时器。

另外,您可以在创建计时器对象时提供info而不是传递null,可能是字符串标识符。它稍后将帮助识别哪个定时器超时或在系统中有多个定时器的情况下取消定时器。

创建定时器&多次重新启动应用程序,有几个这样的定时器具有相同的info,但有不同的hashCode。所以他们不重叠&每次都会创建新的。

您可以通过ctx.getTimerService().getTimers() &取消定时器迭代它们。

编辑:我已复制场景&也面临类似的问题。我有调试&它发生时,有多个以前的定时器活动相同的时间间隔,这是不被取消。

你试试下面的代码,我试过&它解决了这个问题。从文档

for(Timer t : timerService.getTimers()) 
    t.cancel(); //-- Cancel timers before creatimng new one 
ctx.getTimerService().createTimer(1000, 20000, null); 

摘录:

intervalDuration - 如果期满被延迟(例如,由于其他方法的交织呼吁豆),在靠近继承可能发生两个或更多到期通知“跟上来”。

+0

嗨Nayan,感谢您的回应..我遇到的问题是时间总是触发在每30秒。在创建时间时给出的intervalDuration完全被忽略了......你能否让我知道为什么intervalDuration没有被反映出来。我甚至清理了表格并重新部署了时间,但仍然每隔30秒发生一次 –

+0

@EswaramoorthyBabu我根据您的意见删除了帖子,请参阅编辑部分 –

0

您可以使用不同的样式(注释)。见下文:

@Schedule(hour = "*", minute = "*",second = "*/40") 
    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) 
    @Lock(LockType.WRITE) 
    @AccessTimeout(1000 * 60 * 60)//1 Hour...//Concurrent Access is not permitted...