RegistryShutdownListener 抛出异常

发布于 2024-08-18 07:38:23 字数 3664 浏览 3 评论 0原文

根据服务生命周期上的文档我应该能够实现RegistryShutdownListener并整理我的资源(在本例中,关闭线程池),但是它抛出异常,并且似乎正在尝试重新初始化我的服务以执行关闭侦听器!?

2010-01-14 10:59:01,750 [main] ERROR org.apache.hivemind.impl.ShutdownCoordinatorImpl - Unable to shutdown <SingletonProxy for svc.MyService($MyService_1262a1db992)>: Unable to construct service svc.MyService: The HiveMind Registry has been shutdown.
org.apache.hivemind.ApplicationRuntimeException: Unable to construct service svc.MyService: The HiveMind Registry has been shutdown.
    at org.apache.hivemind.impl.servicemodel.AbstractServiceModelImpl.constructNewServiceImplementation(AbstractServiceModelImpl.java:166)
    at org.apache.hivemind.impl.servicemodel.AbstractServiceModelImpl.constructServiceImplementation(AbstractServiceModelImpl.java:140)
    at org.apache.hivemind.impl.servicemodel.SingletonServiceModel.getActualServiceImplementation(SingletonServiceModel.java:69)
    at $$MyService_1262a1db992_1262a1db994._service($$MyService_1262a1db992_1262a1db994.java)
    at $$MyService_1262a1db992_1262a1db994.registryDidShutdown($$MyService_1262a1db992_1262a1db994.java)
    at $$MyService_1262a1db992_1262a1db993.registryDidShutdown($$MyService_1262a1db992_1262a1db993.java)
    at org.apache.hivemind.impl.ShutdownCoordinatorImpl.shutdown(ShutdownCoordinatorImpl.java:97)
    at org.apache.hivemind.impl.ShutdownCoordinatorImpl.shutdown(ShutdownCoordinatorImpl.java:80)
    at org.apache.hivemind.impl.RegistryInfrastructureImpl.shutdown(RegistryInfrastructureImpl.java:379)
    at org.apache.hivemind.impl.RegistryImpl.shutdown(RegistryImpl.java:94)
    at org.apache.tapestry.ApplicationServlet.destroy(ApplicationServlet.java:322)
    at org.apache.catalina.core.StandardWrapper.unload(StandardWrapper.java:1394)
    ...
Caused by: org.apache.hivemind.ApplicationRuntimeException: The HiveMind Registry has been shutdown.
    at org.apache.hivemind.impl.RegistryInfrastructureImpl.checkShutdown(RegistryInfrastructureImpl.java:404)
    at org.apache.hivemind.impl.RegistryInfrastructureImpl.getServicePoint(RegistryInfrastructureImpl.java:153)
    at org.apache.hivemind.impl.ModuleImpl.getServicePoint(ModuleImpl.java:169)
    at org.apache.hivemind.impl.InvokeFactoryServiceConstructor.setupFactoryAndParameters(InvokeFactoryServiceConstructor.java:78)
    at org.apache.hivemind.impl.InvokeFactoryServiceConstructor.constructCoreServiceImplementation(InvokeFactoryServiceConstructor.java:55)
    at org.apache.hivemind.impl.servicemodel.AbstractServiceModelImpl.constructCoreServiceImplementation(AbstractServiceModelImpl.java:108)
    at org.apache.hivemind.impl.servicemodel.AbstractServiceModelImpl.constructNewServiceImplementation(AbstractServiceModelImpl.java:158)
    ... 31 more

Hivemodule.xml:

<service-point id="MyService" interface="package.MyService">
    <invoke-factory><construct class="package.MyService" /></invoke-factory>
</service-point>

package.MyService.java:

public class MyService implements RegistryShutdownListener
{
...
    private ExecutorService executors;

    private void intitialise()
    {
...
    executors = Executors.newFixedThreadPool(3);
...
    }

...

    @Override
    public void registryDidShutdown()
    {
        if (executors.isShutdown())
            return;
        executors.shutdown();
    }
}

ps 我知道您不能在 registryDidShutdown() 中引用另一个 hivemind 服务,但 executors 不是 hivemind 服务 AFAIK,它是 的一部分java.util.concurrent

acording to the docs on service lifecycle i should be able to implement RegistryShutdownListener and tidy up my resources (in this case, shutdown a threadpool) however it is throwing an exception and seems to be trying to re-initialise my service in order to perform the shutdown listener!?

2010-01-14 10:59:01,750 [main] ERROR org.apache.hivemind.impl.ShutdownCoordinatorImpl - Unable to shutdown <SingletonProxy for svc.MyService($MyService_1262a1db992)>: Unable to construct service svc.MyService: The HiveMind Registry has been shutdown.
org.apache.hivemind.ApplicationRuntimeException: Unable to construct service svc.MyService: The HiveMind Registry has been shutdown.
    at org.apache.hivemind.impl.servicemodel.AbstractServiceModelImpl.constructNewServiceImplementation(AbstractServiceModelImpl.java:166)
    at org.apache.hivemind.impl.servicemodel.AbstractServiceModelImpl.constructServiceImplementation(AbstractServiceModelImpl.java:140)
    at org.apache.hivemind.impl.servicemodel.SingletonServiceModel.getActualServiceImplementation(SingletonServiceModel.java:69)
    at $MyService_1262a1db992_1262a1db994._service($MyService_1262a1db992_1262a1db994.java)
    at $MyService_1262a1db992_1262a1db994.registryDidShutdown($MyService_1262a1db992_1262a1db994.java)
    at $MyService_1262a1db992_1262a1db993.registryDidShutdown($MyService_1262a1db992_1262a1db993.java)
    at org.apache.hivemind.impl.ShutdownCoordinatorImpl.shutdown(ShutdownCoordinatorImpl.java:97)
    at org.apache.hivemind.impl.ShutdownCoordinatorImpl.shutdown(ShutdownCoordinatorImpl.java:80)
    at org.apache.hivemind.impl.RegistryInfrastructureImpl.shutdown(RegistryInfrastructureImpl.java:379)
    at org.apache.hivemind.impl.RegistryImpl.shutdown(RegistryImpl.java:94)
    at org.apache.tapestry.ApplicationServlet.destroy(ApplicationServlet.java:322)
    at org.apache.catalina.core.StandardWrapper.unload(StandardWrapper.java:1394)
    ...
Caused by: org.apache.hivemind.ApplicationRuntimeException: The HiveMind Registry has been shutdown.
    at org.apache.hivemind.impl.RegistryInfrastructureImpl.checkShutdown(RegistryInfrastructureImpl.java:404)
    at org.apache.hivemind.impl.RegistryInfrastructureImpl.getServicePoint(RegistryInfrastructureImpl.java:153)
    at org.apache.hivemind.impl.ModuleImpl.getServicePoint(ModuleImpl.java:169)
    at org.apache.hivemind.impl.InvokeFactoryServiceConstructor.setupFactoryAndParameters(InvokeFactoryServiceConstructor.java:78)
    at org.apache.hivemind.impl.InvokeFactoryServiceConstructor.constructCoreServiceImplementation(InvokeFactoryServiceConstructor.java:55)
    at org.apache.hivemind.impl.servicemodel.AbstractServiceModelImpl.constructCoreServiceImplementation(AbstractServiceModelImpl.java:108)
    at org.apache.hivemind.impl.servicemodel.AbstractServiceModelImpl.constructNewServiceImplementation(AbstractServiceModelImpl.java:158)
    ... 31 more

Hivemodule.xml:

<service-point id="MyService" interface="package.MyService">
    <invoke-factory><construct class="package.MyService" /></invoke-factory>
</service-point>

package.MyService.java:

public class MyService implements RegistryShutdownListener
{
...
    private ExecutorService executors;

    private void intitialise()
    {
...
    executors = Executors.newFixedThreadPool(3);
...
    }

...

    @Override
    public void registryDidShutdown()
    {
        if (executors.isShutdown())
            return;
        executors.shutdown();
    }
}

ps i understand that you can't refer to another hivemind service in registryDidShutdown() but executors isn't a hivemind service AFAIK, it's part of java.util.concurrent

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小苏打饼 2024-08-25 07:38:23

找到 this 后,我发现这是一个错误。解决方法是使用服务的接口(我有时会跳过),而不是使用 hivemodule 中的构造和接口的实现。

after finding this i can see that it's a bug. work around is to use an interface for the service (something i skip sometimes) instead of using the implementation for both construction and interface in hivemodule.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文