简体   繁体   English

如何使OSGI EventAdmin处理多个线程中的事件

[英]How to make OSGI EventAdmin handle events in multiple threads

I am developing OSGI project. 我正在开发OSGI项目。 There are lots of services uses event admin, sending and handling events. 有很多服务使用事件管理,发送和处理事件。 And it seems that event admin handles events in a single thread. 而且似乎事件管理员在单个线程中处理事件。 When a handleEvent function is activated, any other handle event function wont starts until running handleEvent function exits. 激活handleEvent函数后,任何其他的handle事件函数都不会启动,直到运行的handleEvent函数退出。 I tested it Thread.sleep function. 我测试了它的Thread.sleep函数。

I wonder if there are any configuration or parameter to make event admin to handle events in a multi-threaded fashion. 我想知道是否有任何配置或参数可以使事件管理员以多线程方式处理事件。

I am using eclipse neon 3 and equinox comes with it. 我正在使用eclipse neon 3和春分。

This depends on the event admin impl you use. 这取决于您使用的事件管理员暗示。 For felix eventadmin the default is to use 20 threads and it is configureable. 对于felix eventadmin ,默认值为使用20个线程,并且它是可配置的。

You also should use eventAdmin.postEvent to ensure async delivery. 您还应该使用eventAdmin.postEvent来确保异步传递。

The spec provides leeway in the number of threads used. 该规范提供了使用的线程数的余地。 However, there is one guarantee that can be costly. 但是,存在一项可能代价高昂的保证。 Events must be delivered in order to a given handler. 必须将事件传递给给定的处理程序。 This constraints parallel delivery. 这限制了并行传送。 You can register a service property event.delivery=async.unordered that will remove this constrain for a handler and allows the Event Admin more leeway in delivering events. 您可以注册服务属性event.delivery=async.unordered ,该属性将消除处理程序的此限制,并允许事件管理员在传递事件方面有更多的余地。

I find it rather hard to believe that the Equinox version would use only one thread ... 我很难相信Equinox版本仅使用一个线程...

To learn more about Event Admin, read the tutorial OSGi Event Admin – Publish & Subscribe 要了解有关事件管理的更多信息,请阅读教程OSGi事件管理–发布和订阅。

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

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