I have some plugin type classes whose thread safety and exception handling I cannot guarantee (let’s say to be coded by some third person in future). The main Application does know these only through a “plugin” Interface, and doesn’t care what they do internally. Except that the application can’t afford to crash or freeze due to some exception thrown or thread lock in these plugin classes. Plugin classes are not dependent on main application, just carry out some commands from main application. Only two other interactions being:
- Call a method of an interface (supplied by main app as method arg) , when asynchronous task complete.
- provide a GUI for configuration. (main application simply asks and adds/removes this from a
JPanelcontainer, nothing more.)
What are some good ways to achieve this ? I’m thinking of a wrapper with Synchronized,try-catch calls to actual plugin methods. Can AOP interceptors be employed here ? Any other way to sandbox a class in Java ?
Turns out you can safeguard most of your processes, but when you agree to show a plugin’s UI on your UI thread, It can definitely crash your application.