OSGi Threading Model

て烟熏妆下的殇ゞ 提交于 2019-12-04 18:18:51

问题


I have searched the Internet but failed to find a satisfactory answer. What is the threading model present in an OSGi container? Does it simply spawn a new thread to each registered bundle e.g.? Any reference regarding the threading model would be great.


回答1:


You have not found anything because there is no such thing as an "OSGi threading model". Bundles simply exist and don't "have threads" unless they start them.




回答2:


The OSGi framework follows a synchronous model, ie. everything happens in a strict order. Bundles are not executed in threads (but they have their own classloader instances). There are some exceptions, though. For example, when an event is raised via the postEvent method, the delivery of the event is done asynchronously, usually implemented in many framework implementations as a thread.




回答3:


When you start a bundle, code in activator is executed in one thread, similar to the 'main' thread. When the main thread completes its execution, bundle is changed from the 'Starting' state to 'Active' state. So it is better to execute time consuming code in another thread and starting another thread from the main thread.

When service method gets called from service consumer. At that time, the code written in the service method get executed in service consumer's thread.

I didn't find any difference between static variables and local variable in the service method.




回答4:


Besides some special cases (Events/Listeners) the application threads are neighter managed nor restricted. You can use threading freely. You do need to be aware that some operations in the bundle lifecylce must be (therefore) thread safe and you need to be very carefull to tear down threads cleanly. You also need to be carefull not to block OSGi operations needlessly long.



来源:https://stackoverflow.com/questions/4117089/osgi-threading-model

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!