Threads: Infinite Loops + Synchronized Methods

With the following Runnable:

publicvoid run{

while(true){

// something

}

}

publicsynchronized method ......{}

Synchronized methods lock the object until the method returns correct?

Would that method never be callable then because run() never returns

and therefore it cant get a lock?

Ive never tried the above code. I usually do the following:

publicvoid run{

while(true){

synchronized(object){

}

// something

}

}

public method ......{

synchronized(object){}

}

And synchronize on an object.

I was just curious if im right about the first case.

[1599 byte] By [TuringPesta] at [2007-11-26 18:12:43]
# 1

non-synchronized methods and synchronized methods have nothing in

common. If a non-synchronized method runs forever another thread can

still call a synchronized method from that same object. The first method

doesn't hold a lock, the second method won't be blocked.

kind regards,

Jos

JosAHa at 2007-7-9 5:45:38 > top of Java-index,Java Essentials,Java Programming...