Multiple WindowsManagerImpl Workaround
Adam Korynta <[email protected]> Fri, 14 Apr 2017 14:53:19 +0000
| Newsgroups | gmane.comp.java.netbeans.modules.openide.devel |
|---|---|
| Message-ID | <CY4PR02MB22466FE820814D5C903BCC1FBD050@CY4PR02MB2246.namprd02.prod.outlook.com> |
Hi All, Recently I have been tasked to open multiple instances of the Netbeans platform within the same JVM from a non-platform application. I was able to successfully launch the netbeans Main.main() method through Reflection but the WindowsManager is very much a strictly enforced singleton. This lead me to launching the platform through my own custom URLClassLoader, which worked all well and dandy, but still subsequent calls to the Netbeans' Main opened the new window in place of my old window. This lead me into an investigation of the ModuleManager.SystemClassLoader and how it enables/disables modules. Apparently the SystemClassLoader gets set on every single running thread by way of getting the top-most ThreadGroup and enumerating the Threads recursively. Obviously this is a problem because I don't want my non-platform application threads to get the Netbeans' SystemClassLoader and if my first Main.main() launch gets all its threads set to subsequent instances' SystemClassLoader then I'm back to having a singleton MainWindow. So I came up with a solution: Netbeans recursively asks for parent ThreadGroups by assuming that the top ThreadGroup has a null parent. The ThreadGroup class itself is pretty locked down tight with final access modifiers everywhere. So I create a new ThreadGroup and through Reflection, force the parent of this thread group to be null. Now I am able to successfully partition Netbeans Platform instances through multiple ThreadGroups. In order to finally get it to work, I also needed to rename the underlying frame to something different than "NbMainWindow". So I have a question for the panel. On a scale of 1 to 10 how hacky is this solution? Am I going to run into some horrible issues down the road? Thank you for your input. Adam Adam Software QA Engineer/Developer 1756 Picasso Avenue, Suite G, Davis, CA 95618 Phone 530-564-7043 ext. 217 Fax 530-231-5323 [email protected] www.rmanet.com