我应该在计划执行器上使用 ejb @Schedule 注释吗
Should I use ejb @Schedule annotation over schedule executor
我正在编写一个每 x 秒调用一次 REST 服务的服务。我可以使用 EJB @Schedule 注释以及 ScheduledExecutorService 来做到这一点。
哪个更好用?为什么?
如果您正在编写 EJB 应用程序,则应使用 Schedule
- EJB 规范要求 EJB should not use threads directly,并表示这样做可能会导致容器出错,以及阻止容器有效地管理资源。
作为交换,Schedule
您将获得容器管理和 EJB 服务的好处。
我正在编写一个每 x 秒调用一次 REST 服务的服务。我可以使用 EJB @Schedule 注释以及 ScheduledExecutorService 来做到这一点。
哪个更好用?为什么?
如果您正在编写 EJB 应用程序,则应使用 Schedule
- EJB 规范要求 EJB should not use threads directly,并表示这样做可能会导致容器出错,以及阻止容器有效地管理资源。
作为交换,Schedule
您将获得容器管理和 EJB 服务的好处。