I have heard that using the low-level OSGi API generally can induce some thread-safety problems, like when registering a service implementation (e.g in this presentation).
Q1. What kind of problems are those? Could someone show an example?
In particular I want to install a JPA bundle (probably EclipseLink) in an OSGi container (Apache Felix) from within my bundle, where the JPA bundle is jarred with my bundle (see this question for details).
Q2. What kind of thread-safety bugs could I have if I simply call BundleContext.installBundle()
? If there are any problems, could "Spring DM" help me solve those problems?
Q1: OSGi bundles live in a concurrent world so any code that is callable by others will give rise to thread safety issues. Q2: Install bundle causes events, these events are delivered on other threads so if you subscribe to those events you must be careful when you share state. Q3: No, Spring DM does not solve this problem for you.
Overall, OSGi actually minimizes concurrency issues if you use the service model with Declarative Services (DS). I find that the strict timing of DS ensures the important happens-before relations that avoids most concurrency issues.