Do all open projects in Intelij 8 have the same class loader?
I am creating a plugin where I have used some singleton classes containing static member objects storing meta-information about current project.
With a single class loader, if more than one project gets opened simultaneously then same instance of the singleton class will be shared by all the projects and hence changes in one project will reflect in the other through the statics.
Is there a way by which we can specify that separate class loaders should be used for every project which is opened?
Edited by: Kunjan on Nov 11, 2008 11:36 AM
Please sign in to leave a comment.
No, AFAIK that's not possible. You have to use a project component (or service) to store project-specific data.
Yes i am using project component.
But the problem is in my VCS i am using singleton classes.
Now suppose I take the instance of a singleton class say, SING, in the project component.
Then i assign value to it's static member variable say, PROJPATH, i.e. the path of the current open project.
Now when another project is opened in a new frame then again project component is invoked which looks for the instance of SING.
Now since there is a single class loader for all projects so, this project component also gets the same instance of SING as shared by the previous project's project component.
So, this time when PROJPATH gets the value , it overrides the value stored previously.
This is the main problem I am having.
So now i'm ending up writing my own custom class loader to load my VCS classes for me.
Yes, I did understand your problem from your first post. My suggestion is to translate your singletons (e.g. SING) into a project component too.
But my singleton's are in my VCS code which is a java application and not an idea plugin.
My plugin does not have singletons but I need to instantiaite the singletons present inside my VCS package to get an access to the member objects.
So i can't actually make them project component because then my VCS would become dependent to intellij API.
Or is there a way by which I can make my VCS singleton classes project component and still have my VCS run for other IDEs also.
I see, that's another situation. Then you probably really have to use your own classloader.
Hello Kunjan,
Yes, all projects use the same classloader. No, there is no way to configure
it differently. You must never store Project or Module instances in static
variables.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"