mercredi 1 avril 2020

Safely caching java reflection objects for reuse

I'm creating a WebLogic Java 7 application that dynamically resolves beans using reflection then accesses the beans using the reflection-resolved getter and setter Method objects. I'm wanting to cache the Method objects for better performance and have at my disposal a caching mechanism that is implemented as a static variable with calls to the cache being synchronized. Currently I'm storing the resolved Method objects inside an object and caching this for retrieval and reuse in later http calls.

My question is - is storing Method and other reflection objects for reuse in this context "safe"? Meaning thread-safe, safe from memory leaks, safe from somehow becoming an outdated or duplicate version or not being able to be successfully deserialized?

Note that these are custom bean objects and no other program logic with be messing with them. And the cache is emptied when the JVM restarts.

Thanks in advance.





Aucun commentaire:

Enregistrer un commentaire