What happens when a OSGi service using JNI is unregistered while in use?
As I understand, OSGi services can be unregistered anytime, including when they are in use.
Consider an OSGi service which internally makes a long-running JNI call. And while that JNI call is executing, the service is unregistered by OSGi.
Will the JNI call be allowed to finish or terminated mid-way? What if it was just a normal non-jni long running Java call? Will that call be allowed to finish execution or will OSGi terminate everything immediately and unregister?
What is the expected behavior in such a case? Does the expected behavior depend on if 开发者_JAVA百科the service was loaded using a 'tracker' or not?
SG
I think even with "normal" (non-JNI) services, OSGi will not stop any processing that is already going on. In fact, if a bundle somehow keeps a reference to a service instance after it has been unregistered (which it is not supposed to do), it can still call methods on that object (whether those will still work or not is entirely dependent on the service implementation).
There is no "magic" going on with OSGi services. The bundle lifecycle just controls what gets registered and unregistered in the service registry. Once you have a reference to a service implementation, it is just plain old Java method calls.
So, to answer you question, unless the bundle (or service) itself does anything to terminate ongoing activity, the long-running call will finish.
精彩评论