简体   繁体   English

使用EJB Timer Service执行外部服务

[英]Executing external services using EJB Timer Service

I have a scenario to ask regarding utilizing the EJB Timer Service. 我有一个关于利用EJB计时器服务的场景。

Use case as follows: The system should be able to schedule a task that will poll/ask our subversion repository for files changes using some particular timestamp. 用例如下:系统应该能够安排一个任务,该任务将使用某些特定的时间戳来轮询/询问我们的Subversion存储库中的文件更改。

The idea is that whenever the scheduled task is about to run, it will execute command against a particular svn repository. 这个想法是,每当计划任务要运行时,它将针对特定的svn存储库执行命令。 For this particular purpose, I will not call any external process but will use the 'pure' java way of using the SVNKit java library http://svnkit.com/ 为此,我不会调用任何外部进程,而是使用“纯” java方式来使用SVNKit Java库http://svnkit.com/

My only concern is this: Is it a good idea to use the EJB Timer Service to execute task that will call external processes? 我唯一关心的是:使用EJB计时器服务执行将调用外部进程的任务是一个好主意吗? My way will use a 'pure' java way but in other scenario such as calling a batch file/command line/external executable directly into the timer service logic. 我的方式将使用“纯” java方式,但在其他情况下,例如将批处理文件/命令行/外部可执行文件直接调用到计时器服务逻辑中。

I worry about the effects of server memory use/performance etc. 我担心服务器内存使用/性能等的影响。

Is this a good idea? 这是一个好主意吗?

The other thought that I am thinking is to just create a 'desktop' application in the server using client based technology such as SWT/Swing that will do the polling and then code the logic there but this will mean that I need to manage two applications. 我在想的另一个想法是,使用基于客户端的技术(例如SWT / Swing)在服务器中创建一个“桌面”应用程序,该应用程序将执行轮询,然后在那里进行逻辑编码,但这意味着我需要管理两个应用程序。 The 'desktop' app that will poll and the 'web' user interface that I will create in Glassfish. 将会轮询的“桌面”应用程序以及我将在Glassfish中创建的“网络”用户界面。

I am leaning towards doing everything in the App server of my choice which is glassfish. 我倾向于在我选择的应用服务器(glassfish)中执行所有操作。

I have used EJB Timer before but it only calls against the database without calling any extenral service and it's just that this scenario came up so I raised a question here to gather more thoughts from those who have experienced doing this. 我以前使用过EJB Timer,但是它只调用数据库而没有调用任何扩展服务,只是这种情况出现了,所以我在这里提出了一个问题,以收集有经验的人的更多想法。

Any thoughts? 有什么想法吗?

In theory, EJBs aren't supposed to depend on external I/O since it interferes with the container/server's management of bean instances, threads, etc. 从理论上讲,EJB不应该依赖于外部I / O,因为它会干扰容器/服务器对Bean实例,线程等的管理。

In practice, this should work if you take precautions. 在实践中,如果采取预防措施,这应该会起作用。 For example: 例如:

  • isolate the function to its own EJB (ie, a stateless session bean that only handles these timers) to avoid instance pooling issues 将函数隔离到自己的EJB(即仅处理这些计时器的无状态会话Bean)以避免实例池问题
  • use timeouts while waiting for commands to avoid hung processes from hanging all server threads 在等待命令时使用超时,以避免挂起的进程挂起所有服务器线程
  • ensure that you don't schedule timers so that you have multiple OS commands run simultaneously 确保您不安排计时器,以便同时运行多个OS命令

Keep in mind that EJB 3.0 timers are persistent (vs EJB 3.1 timers, which have the option of being non-persistent), which means: 请记住,EJB 3.0计时器是持久性的(与EJB 3.1计时器相比,它可以是非持久性的),这意味着:

  1. They can run on any server in a cluster. 它们可以在群集中的任何服务器上运行。 If you have multiple machines in your cluster, you need to ensure that they are all capable of running the command. 如果群集中有多台计算机,则需要确保它们都能运行该命令。
  2. They survive server restarts. 它们在服务器重启后仍然存在。 If you schedule a timer to run but the server crashes before it can, it will run when the server restarts. 如果您安排计时器运行,但服务器先崩溃了,它将在服务器重新启动时运行。 This can cause particular problems for interval timers (all missed timers will fire repeatedly) and if you don't carefully manage existing times (you can easily create redundant timers). 这可能会导致间隔计时器出现特殊问题(所有错过的计时器都会重复触发),如果您不仔细管理现有时间(您可以轻松创建冗余计时器)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM