天道酬勤,学无止境

CommonJ TimerManager versus EJB3 TimerService

I have to implement a simple (not clustered) timer for WebLogic and it seems there are two different 'standard' options

  • Timer and Work Manager API (CommonJ)
  • EJB3.0 TimerService

Does anyone have any advice on using the CommonJ TimerManager versus using the EJB3 TimerService in WebLogic 10.0?

Thank you.

评论

TimerService in EJB 3.0 is somewhat limited as compared to CommonJ Timer Manager. For example, it requires boilerplate code and container-specific configuration to implement flexible task scheduling. This was simplified with the introduction of @Scheduled annotation in EJB 3.1.

If you are stick with EJB 3.0 and need easily and flexibly configurable task scheduling, CommonJ Timer Manager API is a viable option.

In addition, Task Scheduler from Spring Framework (org.springframework.scheduling.TaskScheduler) does a good job of abstracting Timer Manager API and allows declarative configuration using cron expressions.

CommonJ was originally proposed under JSR 237, which was withdrawn in 2008 and merged into JSR 236 Concurrency Utilities for the Java EE platform. Note that this means a significant change from CommonJ proposed standard and API. The name CommonJ is removed, the new packages are under javax.enterprise.concurrent, rather than commonj.timers and commonj.work, and the original classes TimerManager, Timer and TimerListener are replaced by non-corresponding interfaces/classes including ManagedScheduledExecutorService, ManagedTask, ManagedTaskListener, Trigger.

This latter JSR 236 has recently passed public review and, hence, should become a standard soon. As of november 2012, it is a preliminary candidate for inclusion under the Java EE 7 specification (JSR 342), but this will be confirmed once 342 is finalised and released.

Hence, the following problems with CommonJ:

  • it is not and will not be a Java standard, until significantly changed under JSR 236 which will be included in Java EE 7 or later
  • it goes beyond your requirements, presumably, and is more complicated than the EJB 3.0 Timer Service

I suggest you use the EJB 3.0 Timer Service if it meets your needs.

Yes, if TimeService features cover your requirements use it - it's part of the Java EE standard! Why use another library if not absolutely necessary.

受限制的 HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。

相关推荐
  • Spring Data JPA repositories use in EJB timer causes TransactionRequiredException
    I would like to use spring data repositories in my Java EE project. I use: WildFly 10.0.0 Hibernate 5.0.7 Spring Data JPA 1.10.6 CDI instead of Spring DI I have created the following classes and interfaces: @Entity public class TestEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @NotNull @Size(min = 1, max = 32) @Column(name = "name") private String name; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } } My repository @Repository
  • 即使从最近的应用程序清除了应用程序,也继续服务(Continue Service even if application is cleared from Recent app)
    问题 我有一个小问题。 在我的应用程序中,用户成功登录后将启动服务。 以前,如果应用程序被终止,则该服务需要停止。 (例如,通过刷卡从“最近的应用程序”列表中删除。)因此,我们使用了android:stopWithTask="true" 。 现在,即使从“最近使用的应用程序”列表中删除了启动该服务的任务,我们也需要按原样运行该服务。 因此,我将服务更改为包括android:stopWithTask="false" 。 但这似乎不起作用。 相关代码: 这是与服务有关的清单部分: <service android:enabled="true" android:name=".MyService" android:exported="false" android:stopWithTask="false" /> 在MyService.java中: public class MyService extends AbstractService { @Override public void onStartService() { Intent intent = new Intent(this, MyActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP)
  • 在Tomcat中从Servlet产生线程的推荐方法是什么(What is recommended way for spawning threads from a servlet in Tomcat)
    问题 大概重复一遍! 我正在使用Tomcat作为服务器,并且想知道什么是在servlet中产生确定性结果的最佳方式。 我正在从servlet操作中运行一些长期运行的更新,并希望请求完成并在后台进行更新。 我认为我可以生成一个可以在后台运行并在自己的时间内完成的线程,而不是添加像RabbitMQ这样的消息传递中间件。 我在其他SO线程中读到,服务器终止了服务器派生的线程,以使其很好地管理资源。 使用Tomcat时,是否有建议的方法来生成线程,后台作业。 我还将Spring MVC用于该应用程序。 回答1 在像Tomcat或Jetty这样的准系统servlet容器中,最安全的选择是使用最大线程数的applicaton宽线程池,以便在必要时将任务排队。 ExecutorService在此方面非常有帮助。 在应用程序启动或servlet初始化后,使用Executors类创建一个: executor = Executors.newFixedThreadPool(10); // Max 10 threads. 然后在Servlet的服务期间(对于您不感兴趣的情况,您可以忽略结果,或者将其存储在会话中以供以后访问): Future<ReturnType> result = executor.submit(new YourTask(yourData))
  • Flink从入门到真香(16、Flink内置的一些Process Function)
    之前的转换算子是无法访问事件的时间戳信息和水位线信息的,而这在一些应用场景下,极为重要。例如MapFunction这样子的map转换算子就无法访问时间戳或者当前事件的事件事件。 基于此,DataStream API提供了一系列LOW-LEVEL的转换算子调用。可以访问时间戳,watermark以及注册定时事件,还可以输出特定的一些事件,例如超时时间等。process function用来构建事件驱动的应用以及实现自定义的业务逻辑(使用之前的window函数和转换算子无法实现)。例如Flink SQL就是使用Process Function实现的。 Flink提供了8个 Process Function ProcessFunction KeyedProcessFunction CoProcessFunction ProcessJoinFunction BroadcastProcessFunction KeyedBroadcastProcessFunction ProcessWindowFunction 下面几个栗子来一一说明: 栗子1- 实现一个连续15秒如果温度持续上升就报警 package com.mafei.apitest import com.mafei.sinktest.SensorReadingTest5 import org.apache.flink.api
  • Set a Listener in a Service-based Class
    Hy i have a problem to set the ServiceUpdateUIListener in the service to update the UI. It's wrong to make a new Service object and set there the listener and put it in an intent. Code source is at http://developerlife.com/tutorials/?p=356 there i can't find how the set the listener and start the service right. Calling: TimerService service = new TimerService(); TimerService.setUpdateListener(new ServiceUpdateUIListener() { @Override public void updateUI(String time) { clock.setText(time); } }); Intent i = new Intent(Timer.this,service.class); //service cannot be resolved to a type i.putExtra(
  • Flink流处理API——ProcessFunction API (底层API)
    原文链接:https://www.toutiao.com/i6860721527952769539/ 本文主要从以下几个方面介绍Flink流处理API——ProcessFunction API (底层API) 一、产生背景 二、KeyeProcesFunction 三、TimerService和定时器(Timers) 四、侧输出流(SideOutPut) 五、CoProcessFunction 版本: scala:2.11.12 Kafka:0.8.2.2 Flink:1.7.2 <dependencies> <dependency> <groupId>org.apache.flink</groupId> <artifactId>flink-scala_2.11</artifactId> <version>1.7.2</version> </dependency> <dependency> <groupId>org.apache.flink</groupId> <artifactId>flink-streaming-scala_2.11</artifactId> <version>1.7.2</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.flink</groupId>
  • 什么时候需要或方便使用Spring或EJB3或全部一起使用?(When is it necessary or convenient to use Spring or EJB3 or all of them together?)
    问题 我对JSF2 + Spring + EJB3的混合使用或它们的任何组合感到有些困惑。 我知道Spring的主要特征之一是依赖项注入,但是使用JSF托管Bean,我可以使用@ManagedBean和@ManagedProperty批注,并且可以获得依赖项注入功能。 对于EJB3,我更困惑何时与JSF一起使用它,或者甚至有理由使用它。 那么,在哪种情况下使用Spring + JSF2或EJB3 + JSF2是一个好主意? 到现在为止,我仅使用JSF2创建了一些小型Web应用程序,而从未使用过Spring或EJB3。 但是,我在很多地方看到人们正在一起处理所有这些东西。 回答1 首先,Spring和EJB(+ JTA)是竞争技术,通常不能在同一应用程序中一起使用。 选择一个或另一个。 Spring或EJB(+ JTA)。 我不会告诉您选择哪个,我只会告诉您一些历史和事实,以便您更轻松地做出决定。 他们试图解决的主要问题是提供具有自动事务管理功能的业务服务层API。 想象一下,您需要触发多个SQL查询来执行一个业务任务(例如下订单),而其中一个失败,那么您当然会想一切都回滚了,以便数据库保持相同的状态。像以前一样,好像什么也没有发生。 如果您不使用事务,那么数据库将处于无效状态,因为第一批查询实际上已经成功。 如果您熟悉基本的JDBC,则应该知道可以通过以下方法来实现
  • Should Hibernate be able to handle overlapping foreign keys?
    I have a table that has two foreign keys to two different tables with both foreign keys sharing one column: CREATE TABLE ZipAreas ( country_code CHAR(2) NOT NULL, zip_code VARCHAR(10) NOT NULL, state_code VARCHAR(5) NOT NULL, city_name VARCHAR(100) NOT NULL, PRIMARY KEY (country_code, zip_code, state_code, city_name), FOREIGN KEY (country_code, zip_code) REFERENCES Zips (country_code, code), FOREIGN KEY (country_code, state_code, city_name) REFERENCES Cities (country_code, state_code, name) ) As you can see, there are two FKs sharing country_code (coincidentally referencing the same column at
  • 为JPA中的列设置默认值(Setting default values for columns in JPA)
    问题 可以为JPA中的列设置默认值吗?如果使用注释,如何做到这一点? 回答1 实际上,在JPA中是可能的,尽管使用@Column批注的columnDefinition属性有些小小的@Column ,例如: @Column(name="Price", columnDefinition="Decimal(10,2) default '100.00'") 回答2 您可以执行以下操作: @Column(name="price") private double price = 0.0; 那里! 您刚刚使用零作为默认值。 请注意,如果您仅从此应用程序访问数据库,这将为您提供服务。 如果其他应用程序也使用该数据库,则应使用Cameron的columnDefinition批注属性或其他方式从数据库中进行此检查。 回答3 另一种方法是使用javax.persistence.PrePersist @PrePersist void preInsert() { if (this.createdTime == null) this.createdTime = new Date(); } 回答4 在2017年,JPA 2.1仍然只有@Column(columnDefinition='...') ,您在其中放置了该列的文字SQL定义。 这是非常不灵活的,迫使您也声明其他方面,例如类型
  • Batch inserts with JPA/EJB3
    Does JPA/EJB3 framework provide standard way to do batch insert operation...? We use hibernate for persistence framework, So I can fall back to Hibernate Session and use combination session.save()/session.flush() achieve batch insert. But would like to know if EJB3 have a support for this...
  • Should I use EJB3 or Spring for my business layer?
    My team is developing a new service oriented product with a web front-end. In discussions about what technologies we will use we have settled on running a JBoss application server, and Flex frontend (with possible desktop deployment using Adobe AIR), and web services to interface the client and server. We've reached an impasse when it comes to which server technology to use for our business logic. The big argument is between EJB3 and Spring, with our biggest concerns being scalability and performance, and also maintainability of the code base. Here are my questions: What are the arguments for
  • Can @Resource be used to inject primitives in EJB3.0?
    Using Glassfish, I can setup a string jndi entry: JNDI name: "com/xyzcompany/echo/EchoServiceBean/viewName" Factory Class: org.glassfish.resources.custom.factory.PrimitivesAndStringFactory Properties: value="Testing123" I can then inject this container configured string into my EJB: @Resource(lookup = "com/xyzcompany/echo/EchoServiceBean/viewName") String viewName; The lookup= appears to internally do an InitialContext.lookup(...). However, this uses ejb3.1, but unfortunately my prod environment is only ejb3.0. I guess i'm trying to figure out is there a way to use @Resource(name=) or
  • Spring Boot + JPA:列名注释被忽略(Spring Boot + JPA : Column name annotation ignored)
    问题 我有一个依赖项spring-boot-starter-data-jpa的Spring Boot应用程序。 我的实体类具有带有列名称的列注释。 例如: @Column(name="TestName") private String testName; 由此创建的test_name生成的SQL作为列名。 寻找解决方案后,我发现spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy解决了该问题(列名取自列注释)。 我的问题仍然是,为什么在没有将naming_strategy设置为EJB3NamingStrategy JPA会忽略列注释? 也许休眠方言与此有关? 我正在连接到MS SQL 2014 Express,我的日志包含: Unknown Microsoft SQL Server major version [12] using SQL Server 2000 dialect Using dialect: org.hibernate.dialect.SQLServerDialect 回答1 对于hibernate5,我通过将下一行放在application.properties文件中解决了此问题: spring.jpa.hibernate.naming.implicit-strategy
  • 除了EAR和EJB,我还可以从Java EE应用服务器中获得什么,而从Tomcat之类的servlet容器中得到什么呢?(Besides EAR and EJB, what do I get from a Java EE app server that I don't get in a servlet container like Tomcat?)
    问题 我们使用Tomcat托管基于WAR的应用程序。 我们是servlet容器兼容的J2EE应用程序,但org.apache.catalina.authenticator.SingleSignOn除外。 我们被要求迁移到商用Java EE应用服务器。 我认为进行更改的第一个缺点是成本。 无论对应用程序服务器收费多少,Tomcat都是免费的。 其次是复杂性。 我们既不使用EJB功能也不使用EAR功能(当然不使用,我们不能使用),并且也没有错过它们。 那我看不到的好处是什么? 我没有提到的缺点是什么? 提到的是... JTA-Java交易API-我们通过数据库存储过程控制交易。 JPA-Java持久性API-我们使用JDBC并再次使用存储过程进行持久化。 JMS-Java消息服务-我们在HTTP上使用XML进行消息传递。 很好,请更多! 回答1 除非您希望EJB正确,否则就不需要全栈J2EE服务器(无论是否商用)。 您可以拥有大多数J2EE功能(例如JTA,JPA,JMS,JSF),而无需完整的J2EE服务器堆栈。 全栈j2ee的唯一好处是,容器将代表您声明性地管理所有这些。 随着EJB3的到来,如果您需要容器管理的服务,那么使用它是一件好事。 您也可以免费使用全栈服务器,例如Glasfish,Geronimo或JBoss。 例如,您也可以在Tomcat内部
  • java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet error
    Not sure why am I getting this error. Lots of similar questions here but none have worked for me till now. My ivy file is <ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd"> <info organisation="" module="knoxWeb" status="integration"> </info> <dependencies> <dependency org="org.springframework" name="spring-core" rev="4.0.3.RELEASE"/> <dependency org="org.springframework" name="spring-context" rev="4.0.3.RELEASE"/> <dependency org="org.springframework" name="spring-web" rev="4.0.3.RELEASE"/>
  • java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.ejb.Ejb3Configuration
    I am new to EJB. My manager told me to deploy an ejb application in our test server for some modification. The application is already running in our production server. But when I deploy the application, I am getting an exception. we are using Glassfish Application Server Stack Trace of Exception: java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.ejb.Ejb3Configuration at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:130) at com.sun.enterprise.server.PersistenceUnitLoaderImpl.load(PersistenceUnitLoaderImpl.java:149) at
  • Flink实战-订单支付和对账情况监控(分别使用CEP和ProcessFunction来实现)
    在电商网站中,订单的支付作为直接与钱挂钩的一环,在业务流程中非常重要。对于订单而言,为了正确控制业务流程,也为了增加用户的支付意愿,网站一般会设置一个支付失效时间,超过一段时间没支付的订单就会被取消。另外,对于订单的支付,还应该保证最终支付的正确性,可以通过第三方支付平台的交易数据来做一个实时对账 第一个实现的效果,实时获取订单数据,分析订单的支付情况,分别实时统计支付成功的和15分钟后支付超时的情况 新建一个maven项目,这是基础依赖,如果之前引入了,就不用加了 <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> <flink.version>1.10.1</flink.version> <scala.binary.version>2.12</scala.binary.version> <kafka.version>2.2.0</kafka.version> </properties> <dependencies> <dependency> <groupId>org.apache.flink</groupId> <artifactId>flink-scala_${scala.binary.version}<
  • Best current framework for unit testing EJB3 / JPA [closed]
    Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago. Improve this question Starting a new project using EJB 3 / JPA, mainly stateless session beans and batch jobs. I've used JUnit in the past on standard Java webapps and it seemed to work pretty well. In EJB2 unit testing was a pain and required a running container such as JBoss to make the calls into. Now that we're going to be working in EJB3 / JPA I'd like to know what
  • JPA 2.0 : Exception to use javax.validation.* package in JPA 2.0
    when i try to using bean validation with JPA using hibernate , the follwoing exception will occur : Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: Chapter11] Unable to build EntityManagerFactory at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
  • Detach an entity from JPA/EJB3 persistence context
    What would be the easiest way to detach a specific JPA Entity Bean that was acquired through an EntityManager. Alternatively, could I have a query return detached objects in the first place so they would essentially act as 'read only'? The reason why I want to do this is becuase I want to modify the data within the bean - with in my application only, but not ever have it persisted to the database. In my program, I eventually have to call flush() on the EntityManager, which would persist all changes from attached entities to the underyling database, but I want to exclude specific objects.