On Wed, 02 Apr 2003 15:35:39 -0300
Barzilai Spinak <[EMAIL PROTECTED]> wrote:
> The static portions of a class are normally executed when the class
> is loaded.
> As I understand, the static variables are initialized at that time, or
>
> when the program first references
> the variables.
Right, I understand all that 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