This would be best asked in the osgi-dev list since it is not a felix specific issue.
But ServiceTracker is designed to be thread safe (I wrote most of the code and maintain it). Therefore STC implementations need to be thead safe as well. > Section 6.1.21 of the OSGi R4 core specification reads: > > ,---- > | When a ServiceEvent is fired, it is synchronously delivered to a > | BundleListener. > `---- > Wow. Change history for that file makes it my mistake... I have fixed it for 4.1. Thanks. What the sentence is saying is that ServiceEvents are delivered synchronously from the action that caused the event (e.g. register service, etc.) and the action is blocked from completion until all interested service listeners have been called and returned. A service listener can be called by multiple threads delivering service events and can be reentered by the same thread if the listener takes some action which fires a service event. Net: STC implementation must be thread safe. BJ Hargrave Senior Technical Staff Member, IBM OSGi Fellow and CTO of the OSGi Alliance [EMAIL PROTECTED] office: +1 386 848 1781 mobile: +1 386 848 3788 "Steven E. Harris" <[EMAIL PROTECTED]> 02/16/2007 01:14 PM Please respond to felix-dev@incubator.apache.org To felix-dev@incubator.apache.org cc Subject Confusion about concurrency in ServiceListener/ServiceTracker callbacks I'm confused as to whether a ServiceListener can be called on from multiple threads by the OSGi framework, say, if two service-related events occurred "at the same" time by different threads registering and unregistering services. The question extends to ServiceTracker and its ServiceTrackerCustomizer: Can the addingService(), modifiedService(), and removedService() methods be called on concurrently, meaning that their operation must be made thread-aware? Section 6.1.21 of the OSGi R4 core specification reads: ,---- | When a ServiceEvent is fired, it is synchronously delivered to a | BundleListener. `---- Aside from it looking like "BundleListener" should probably be "ServiceListener", the sentence sounds like it's saying that only one ServiceEvent will be delivered to a ServiceListener at a time. Is that true? If so, can I also conclude that a ServiceTrackerCustomizer will only be called on by one thread at a time? I ask because the ServiceTrackerCustomizer implementation has some synchronized blocks that are attempting to protect some of its data against concurrent access, but the user-provided callback functions are called on outside of those synchronized regions. -- Steven E. Harris