Search code examples
javareflections

Is org.reflections.Reflections thread safe


To avoid having to create multiple instances of the org.reflections.Reflections class I was thinking of just creating one and reusing as needed. Anyone know if this class is thread safe?

If its not thread safe I know I can use Java's ThreadLocal wrapper (in case anyone was going to respond with that).


Solution

  • You can definitely create only one instance, and use it many times.

    The rational is that the Reflection's storage is only populated at scan time (that is, when instantiating it), and queries later on are read only, with defensive copy semantics.