【问题标题】:ejb poller always triggers at every 30 secondsejb poller 总是每 30 秒触发一次
【发布时间】:2012-12-18 16:20:40
【问题描述】:

我创建了 EJB 3 Timer 并将其部署到 weblogic 集群中。 createTimer 参数为 createTimer(1000, 20000, null); 这应该每 20 秒创建一次重复计时器。但是计时器总是每 30 秒创建一次。我什至将 intervalDuration 更改为 40 和 50 秒,但超时方法总是每 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

谁能帮我调查一下为什么计时器总是每 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>

提前致谢

【问题讨论】:

    标签: ejb-3.0 weblogic-10.x


    【解决方案1】:

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


    默认情况下计时器是持久的,因此您必须在启动新计时器之前取消之前的计时器。

    另外,您可以在创建计时器对象时提供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 - 如果过期延迟(例如,由于 bean 上的其他方法调用的交错),可能会连续出现两个或多个过期通知以“赶上”。

    【讨论】:

    • 嗨 Nayan,感谢您的回复。我遇到的问题是时间总是每 30 秒触发一次。创建时间时给出的 intervalDuration 完全被忽略了......你能告诉我为什么没有反映 intervalDuration 吗?我什至清理了表格并重新部署了时间,但它仍然每 30 秒发生一次
    • @EswaramoorthyBabu 我已经根据您的 cmets 发布了帖子,请参阅编辑部分
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-13
      • 2012-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-06
      相关资源
      最近更新 更多