java 设置/配置 EJB 计时器服务的数据源

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13292473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 12:09:46  来源:igfitidea点击:

Set/configure the EJB Timer Service’s DataSource

javajakarta-eeglassfishejb-3.1

提问by ejohansson

I'm trying to use the Timer Service in EJB 3.1 in my app.

我正在尝试在我的应用程序中使用 EJB 3.1 中的计时器服务。

@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());
    }
}

".. set the EJB Timer Service's Timer DataSource setting to a valid JDBC resource.."

“.. 将 EJB 计时器服务的计时器数据源设置设置为有效的 JDBC 资源..”

from EJB Timer Service

来自EJB 定时器服务

I cannot figure out how to configure the Timer Datasource correctly?

我不知道如何正确配置计时器数据源?

The error I get when deploying is:

我在部署时遇到的错误是:

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

Running: glassfish-3.1.2.2

运行: glassfish-3.1.2.2

回答by ejohansson

1. Example Database Setup

1. 示例数据库设置

  1. I use MySQL for my database.

  2. Create the table EJB__TIMER__TBLfrom {GF_HOME}/glassfish/lib/install/databases/ejbtimer_{DB_ENGINE}.sql

  1. 我的数据库使用 MySQL。

  2. EJB__TIMER__TBL从创建表{GF_HOME}/glassfish/lib/install/databases/ejbtimer_{DB_ENGINE}.sql

DB_ENGINE = e.g MySQL:

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. Server Configuration

2. 服务器配置

GlassFish Admin Console

GlassFish 管理控制台

  1. Start your GlassFish server admin console: usually http://localhost:4848
  2. On your left navigate to [Configurations] > [server-config] > [EJB Container]
  3. Then click the TABup top [EJB Timer Service]
  4. Then fill out Timer Datasource: with your JDBC Resource eg. [mysql-pu]. ( Note:Defaults to jdbc/__TimerPool)
  5. Restartthe Server
  1. 启动您的 GlassFish 服务器管理控制台:通常 http://localhost:4848
  2. 在您的左侧导航到[Configurations] > [server-config] > [EJB Container]
  3. 然后单击顶部的TAB [EJB Timer Service]
  4. 然后填写Timer Datasource: 使用您的 JDBC 资源,例如。[mysql-pu]。( 注意:默认为jdbc/__TimerPool
  5. 重启服务器

3. The Result

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. Still Broken? TimerService just stopped working (it used to work)?

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

So this happened to me after a day full of "deploy on save". The TimerService was unavailable all of a sudden.

因此,在充满“保存部署”的一天之后,这发生在我身上。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. Useful Links

5. 有用的链接

回答by Jose Tepedino

In JBoss/WildFly, you can follow these instructions:

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

Mastertheboss.com: Creating clustered EJB 3 Timers
Published: 08 March 2015

Mastertheboss.com:创建集群 EJB 3 计时器
发布时间:2015 年 3 月 8 日

回答by favrycio

That sounds like the glassfish-3.1.2.2 does not support EJB3, try to use jboss 7.

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

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

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