On Fri, 4 Apr 2003 10:48:34 +0100
"Andrew Rendle" <[EMAIL PROTECTED]> wrote:

> Take a look at the following links. I think they explain the Singleton
> problem_. but not understanding all of it, I could be wrong!!!

Thanks for the links - they're great! I'm still confused a bit of
whether just making static members of a class would usually solve my
problem. In other words ...

SomeClass {
  
   static List someList1 = SomeClass.getList1();
   static List someList2 = SomeClass.getList2();

   //rest of class
}

The question I have has more to do with how the statics are set up. I
understand the first time "SomeClass" is referenced it will first go
through and initialize all the static members, but what happens if two
separate threads are accesing "SomeClass" for the first time at about
the same time? Are all static members and blocks synchronized in a sense
at load time? My other post explains my question a bit more thoroughly:

-----

<snip> ... but how does the JVM handle the "loading"
when two or more threads are referencing the class holding the static
members at almost the same instance in time. In other words, I'm
assuming once a static portion of code is accessed it locks out any
other threads from accessing the static portions of the class until the
first thread completes loading the class? I just wasn't sure if maybe
another thread could possibly be messing with the static stuff of the
class if it starts about the same time. Imagine...

thread A starts and calls  Test.method1()
thread B starts at about the same time and calls Test.method2()

//Test class

static int varV;
 
static { 
 //some LONG Process
 varV = 5;
}

static method1() { }
static int method2() { return varV; } 

I'm assuming that the first thread to hit "Test" will start the static
block.... but is it possible that Test.method2() could return "0" before
the static block gets to setting varV = 5 OR does threadB have to wait
until threadA finishes completing it's static block? ( I know, I
know...I've broken my own rule.... test it yourself dumb ass:)



-- 
Rick Reumann

---
You are currently subscribed to jdjlist as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
http://www.sys-con.com/fusetalk

Reply via email to