S
steve.chambers
Help!!!
I'm testing a class that has a particularly stubborn private static
member variable. This variable is initialised in the class's
constructor like this:
myClass {
private static myStaticVariable = null;
// Constructor
public myClass() {
// Initialise private static variable
if (myStaticVariable == null) {
myStaticVariable = something;
}
}
...
}
and then as I understand it the private static member will never change
until all instances of the class are destroyed.
But at various points in my test I need to make sure that the private
static variable *does* get reinitialised to 'something' in the
constructor when a new object is created (I won't bore you with why I
need to do this). I'm not allowed to redesign the class so I can't add
a "setter" method for this variable or make it public. So what I really
need to do is make sure that all previously use objects of this are
garbage collected...
....So in my test I've tried putting in a couple of "Thread.sleep()"s
and a couple of "System.gc()"s in order to give Java plenty of time to
garbage collect but it just doesn't seem to take the hint - once
myStaticVariable has been initialised it seems very reluctant to
uninitialise itself!
Can anyone help with this or is it just one of those Java annoyances
that can't be fixed??
Thanks for any help & suggestions...
Cheers, Steve
I'm testing a class that has a particularly stubborn private static
member variable. This variable is initialised in the class's
constructor like this:
myClass {
private static myStaticVariable = null;
// Constructor
public myClass() {
// Initialise private static variable
if (myStaticVariable == null) {
myStaticVariable = something;
}
}
...
}
and then as I understand it the private static member will never change
until all instances of the class are destroyed.
But at various points in my test I need to make sure that the private
static variable *does* get reinitialised to 'something' in the
constructor when a new object is created (I won't bore you with why I
need to do this). I'm not allowed to redesign the class so I can't add
a "setter" method for this variable or make it public. So what I really
need to do is make sure that all previously use objects of this are
garbage collected...
....So in my test I've tried putting in a couple of "Thread.sleep()"s
and a couple of "System.gc()"s in order to give Java plenty of time to
garbage collect but it just doesn't seem to take the hint - once
myStaticVariable has been initialised it seems very reluctant to
uninitialise itself!
Can anyone help with this or is it just one of those Java annoyances
that can't be fixed??
Thanks for any help & suggestions...
Cheers, Steve