由ServiceRegistry阻止的线程

时间:2014-01-31 17:25:26

标签: osgi osgi-bundle osgi-fragment

我有一个相对较高的音量/请求系统,我们正在使用OSGi。我们每天接近800M请求。

我们目前看到线程被阻止的一些问题。对于每个进入的请求,我们使用registerService将事件/数据转发到osgi包,以将有效负载/数据传递给正在侦听此服务的OSGi包。

像这样:bundleContext.registerService(Map.class.getName(),dataHolderMap,null);

其中dataHolderMap只是一个普通的java hashmap

这是使用JStack的threaddump:

=============================================== ============================

" RequestThread" prio = 10 tid = 0x00000000421ab800 nid = 0x1042 runnable [0x00007fbdd3867000]    java.lang.Thread.State:RUNNABLE         在org.apache.felix.framework.ServiceRegistry.getService(ServiceRegistry.java:295)          - 已锁定< 0x0000000700e2c590> (a org.apache.felix.framework.ServiceRegistry)         在org.apache.felix.framework.Felix.getService(Felix.java:3568)         在org.apache.felix.framework.BundleContextImpl.getService(BundleContextImpl.java:468)         在org.osgi.util.tracker.ServiceTracker.addingService(ServiceTracker.java:411)         在org.osgi.util.tracker.ServiceTracker $ Tracked.customizerAdding(ServiceTracker.java:932)         在org.osgi.util.tracker.ServiceTracker $ Tracked.customizerAdding(ServiceTracker.java:864)         在org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)         在org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229)         在org.osgi.util.tracker.ServiceTracker $ Tracked.serviceChanged(ServiceTracker.java:894)         at org.apache.felix.framework.util.EventDispatcher.invokeServiceListenerCallback(EventDispatcher.java:932)         在org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:793)         在org.apache.felix.framework.util.EventDispatcher.fireServiceEvent(EventDispatcher.java:543)         在org.apache.felix.framework.Felix.fireServiceEvent(Felix.java:4419)         在org.apache.felix.framework.Felix.registerService(Felix.java:3423)         在org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:346)         在org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:320)         在com.mypackage.person.bs.processor.Processor.sendEvent(Processor.java:56)         at com.mypackage.jetMyStream.event.support.AbstractEventSource.fireSendEvent(AbstractEventSource.java:97)         at com.mypackage.jetMyStream.event.channel.messaging.InboundMessagingChannel.fireEvent(InboundMessagingChannel.java:113)         at com.mypackage.jetMyStream.event.channel.messaging.InboundMessagingChannel.onMessage(InboundMessagingChannel.java:204)         at com.mypackage.jetMyStream.messaging.MessageService.dispatchMessageForContext(MessageService.java:349)         at com.mypackage.jetMyStream.messaging.MessageService.dispatch(MessageService.java:259)         at com.mypackage.jetMyStream.messaging.MessageServiceRequest.execute(MessageServiceRequest.java:40)         在com.mypackage.jetMyStream.util.RequestThread.run(RequestThread.java:69)

" RequestThread" prio = 10 tid = 0x00000000425f8800 nid = 0x1041等待监视器输入[0x00007fbdd3968000]    java.lang.Thread.State:BLOCKED(在对象监视器上)         在org.apache.felix.framework.ServiceRegistry.registerService(ServiceRegistry.java:109)          - 等待锁定< 0x0000000700e2c590> (a org.apache.felix.framework.ServiceRegistry)         在org.apache.felix.framework.Felix.registerService(Felix.java:3393)         在org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:346)         在org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:320)         在com.mypackage.person.bs.processor.Processor.sendEvent(BullseyeModelProcessor.java:56)         at com.mypackage.jetMyStream.event.support.AbstractEventSource.fireSendEvent(AbstractEventSource.java:97)         at com.mypackage.jetMyStream.event.channel.messaging.InboundMessagingChannel.fireEvent(InboundMessagingChannel.java:113)         at com.mypackage.jetMyStream.event.channel.messaging.InboundMessagingChannel.onMessage(InboundMessagingChannel.java:204)         at com.mypackage.jetMyStream.messaging.MessageService.dispatchMessageForContext(MessageService.java:349)         at com.mypackage.jetMyStream.messaging.MessageService.dispatch(MessageService.java:259)         在com.mypackage.jetMyStream.messaging.MessageServiceRequest.execute(MessageServiceRequest.java:40)

at com.mypackage.jetMyStream.util.RequestThread.run(RequestThread.java:69)

有关这方面的几个问题:

  1. 我是否在通过registerService发送地图时出错了。如果是的话,我的替代方案是什么?

  2. 关于如何让它发挥作用的任何想法?我们有26个节点,需要使用这种机制每秒处理大约400个请求

    有人有过类似的问题吗?任何指针都非常受欢迎

  3. 由于 Masti

1 个答案:

答案 0 :(得分:6)

“我在通过registerService发送地图时做错了。如果有,我的替代方案是什么?”

YES!服务注册表不打算以这种方式使用;它不是消息传送总线。

至于替代方案......为什么不使用短信总线?你可以看看OSGi Event Admin,但是这个想法有很多其他的实现。

“关于如何使其工作的任何想法?我们有26个节点,并且只需要使用这种机制每秒处理大约400个请求”

你必须更加具体地了解你想要实现的目标。这个问题太抽象了。请描述消息的来源,需要交付的地方,中间需要处理的内容(如果有的话)等。