> I'm using eclipse to launch classes with a static main and other static
> members.
>
> Question: the class takes several minutes to complete, and during that
> time I may have updated the class, recompiled, and launched it again.
> Will the two classes share the same static values?
You could test this by writing a class that has a single static variable
and just goes in an infinite loop, printing out the contents of that static
variable. Initialize the variable to some value "1", and run it.
Then, edit the class so that now the value is initialized to "2" and run
it. Did the changes affect the first class?
> I've asked several of my colleagues. Some yes's, some no's. I say no.
> It's also been suggested I should refactor the class to not use static
> members for configuration parameters.
It probably depends on whether Eclipse runs programs in the same VM, or
creates a new VM for every program. Even if it's the same VM, might depend
on whether Eclipse fiddles with the ClassLoader (so that two instances of
the class object are loaded, each with their own member variable to
represent your static variable, or if only one instance is loaded).
Since the answer is not immediately apparent (and since it may even
change in future optimizations of the Eclipse platform), you should probably
write your code in such a way so that it doesn't depend on any one specific
behaviour (i.e. don't use static members if it'll be a problem for you).
- Oliver
nmlaney@hotmail.com - 29 Oct 2005 16:14 GMT
I did as you suggested, and the static members are NOT shared between
launches within eclipse. Thanks to everyone who responded.
Neill
> I'm using eclipse to launch classes with a static main and other static
> members.
[quoted text clipped - 10 lines]
>
> Neill
No. Each run creates new JVM.
fangsoft.com@gmail.com - 28 Oct 2005 16:13 GMT
no,absolute no. class depends on class loader, Different class loaders
load class in different name space. So JVMs don't share Classes. But in
Jdk1.5 can share Class. You can refer to documents.