OSGi Threading Model

后端 未结 4 1186
独厮守ぢ
独厮守ぢ 2021-02-14 15:13

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 regist

相关标签:
4条回答
  • 2021-02-14 15:53

    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.

    0 讨论(0)
  • 2021-02-14 15:53

    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.

    0 讨论(0)
  • 2021-02-14 15:56

    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.

    0 讨论(0)
  • 2021-02-14 15:56

    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.

    0 讨论(0)
提交回复
热议问题