Re: Multiple WindowsManagerImpl Workaround
geertjan wielenga <[email protected]> Sat, 15 Apr 2017 17:43:06 +0200
| Newsgroups | gmane.comp.java.netbeans.modules.openide.devel |
|---|---|
| Organization | Oracle Corporation |
| Message-ID | <[email protected]> |
On 14-4-2017 16:53, Adam Korynta wrote: > > Hi All, > > Recently I have been tasked to open multiple instances of the Netbeans > platform within the same JVM from a non-platform application. > The question is: WHY you need to do this. The reason I am asking you for the WHY is that possibly the solution is different to what you think or what you think you need. So, can you provide some context for this scenario? Thanks, Gj > 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/// >