设置/配置EJB Timer Service的DataSource

时间:2012-11-08 15:47:54

标签: java java-ee glassfish ejb-3.1

我正在尝试在我的应用程序中使用EJB 3.1中的Timer Service。

@Stateless
@LocalBean
public class StatelessTimerSessionBean {

    @Schedule(minute = "*", second = "0", dayOfMonth = "*", month = "*", year = "*", hour = "9-17", dayOfWeek = "Mon-Fri")
    public void myTimer() {
        System.out.println("Timer event: " + new Date());
    }
}
  

“..将EJB Timer Service的Timer DataSource设置设置为有效的JDBC资源..”

来自EJB Timer Service

我无法弄清楚如何正确配置Timer Datasource?

部署时遇到的错误是:

SEVERE: Exception while invoking class org.glassfish.ejb.startup.EjbApplication start method
java.lang.RuntimeException: EJB Timer Service is not available

跑步:glassfish-3.1.2.2

3 个答案:

答案 0 :(得分:28)

1。示例数据库设置

  1. 我使用MySQL作为我的数据库。

  2. EJB__TIMER__TBL

  3. 创建表格{GF_HOME}/glassfish/lib/install/databases/ejbtimer_{DB_ENGINE}.sql

    DB_EN​​GINE =例如MySQL:

    CREATE TABLE EJB__TIMER__TBL (
        `CREATIONTIMERAW`      BIGINT        NOT NULL,
        `BLOB`                 BLOB,
        `TIMERID`              VARCHAR(255)  NOT NULL,
        `CONTAINERID`          BIGINT        NOT NULL,
        `OWNERID`              VARCHAR(255)  NULL,
        `STATE`                INTEGER       NOT NULL,
        `PKHASHCODE`           INTEGER       NOT NULL,
        `INTERVALDURATION`     BIGINT        NOT NULL,
        `INITIALEXPIRATIONRAW` BIGINT        NOT NULL,
        `LASTEXPIRATIONRAW`    BIGINT        NOT NULL,
        `SCHEDULE`             VARCHAR(255)  NULL,
        `APPLICATIONID`        BIGINT        NOT NULL,
        CONSTRAINT `PK_EJB__TIMER__TBL` PRIMARY KEY (`TIMERID`)
    );
    

    2。服务器配置

    GlassFish Admin Console

    1. 启动GlassFish服务器管理控制台:通常为http://localhost:4848
    2. 在左侧导航至 [配置]> [server-config]> [EJB容器]
    3. 然后点击 TAB 顶部 [EJB计时器服务]
    4. 然后用您的JDBC资源填写计时器数据源:例如。 [MySQL的普]。 (Note: Defaults to jdbc/__TimerPool
    5. 重新启动服务器
    6. 3。结果

      ...
      INFO: [TimerBeanContainer] Created  TimerBeanContainer: TimerBean
      INFO: EJB5181:Portable JNDI names for EJB TimerBean: [java:global/ejb-timer-service-app/TimerBean, java:global/ejb-timer-service-app/TimerBean!com.sun.ejb.containers.TimerLocal]
      INFO: WEB0671: Loading application [ejb-timer-service-app] at [/ejb-timer-service-app]
      INFO: EJB5109:EJB Timer Service started successfully for data source [mysql-pu]
      INFO: Setting DBReadBeforeTimeout to false
      INFO: ==> Restoring Timers ... 
      INFO: There are no EJB Timers owned by this server
      INFO: <== ... Timers Restored.
      ...
      

      4。仍然破碎? TimerService刚刚停止工作(它曾经工作过)?

      所以在经过一整天的“部署保存”之后发生了这件事。 TimerService突然无法使用。

      Severe:   Exception while loading the app
      Severe:   Undeployment failed for context /ejb-timer-service-app
      Warning:   Cannot deploy or load EJBTimerService: org.glassfish.deployment.common.DeploymentException: Error in linking security policy for ejb-timer-service-app -- Inconsistent Module State
      

      <强> Solution Found Here

      5。有用的链接

答案 1 :(得分:0)

在JBoss / WildFly中,您可以按照以下说明操作:

Mastertheboss.com: Creating clustered EJB 3 Timers
发布时间:2015年3月8日

答案 2 :(得分:-3)

听起来像glassfish-3.1.2.2不支持EJB3,尝试使用jboss 7.

http://docs.oracle.com/cd/E26576_01/doc.312/e24939/release-notes.htm