How to Share a Singleton Object Across MuleSoft Applications?

April 26, 2025 1 answer
Asked by Merry
I'm working on a MuleSoft project where I have developed a custom connector that will be used by multiple applications upon deployment. My goal is to share the same singleton object on the boot-up of each app. However, I'm facing challenges because Mule's classloaders are fairly restrictive and specific to each app. Does anyone know a way to allow all deployed apps to access the initial static object? I've tried various approaches, like switching to parent classloaders and using custom URL loaders, but the other applications still can't see it.

Answers

biscuit tin
It sounds like the default behavior is causing issues because of how the classloaders work. You might need to access the System ClassLoader using ClassLoader.getSystemClassLoader(). This way, you can load your class from there. Usually, you can cache it by using ThreadLocals or by creating a custom classloader and binding it to Thread.currentThread.getContextClassLoader(). Give that a shot!

11.after.noon: I appreciate the tip! Do you have any more resources or references for deeper understanding? I'm a bit worried because I think I've already tried the system classloader without success.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions