Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

threads and static members

Thread view: 
nmlaney@hotmail.com - 28 Oct 2005 15:38 GMT
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?

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.

TIA

Neill
Oliver Wong - 28 Oct 2005 15:46 GMT
> 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
Vova Reznik - 28 Oct 2005 15:56 GMT
> 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.