How to Share a Singleton Object Across MuleSoft Applications?

0
6
Asked By CreativeCoder42 On

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.

1 Answer

Answered By TechGuru88 On

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!

CodeNinja99 -

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.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.