Simple java synchronization question
Posted
by Misha Koshelev
on Stack Overflow
See other posts from Stack Overflow
or by Misha Koshelev
Published on 2010-06-12T03:34:15Z
Indexed on
2010/06/12
4:02 UTC
Read the original article
Hit count: 293
java
|synchronized
I was wondering, which is correct:
Option One
class A {
public void methodOne() {
synchronized(this) {
modifyvalue
notifyAll()
}
}
public void methodTwo() {
while (valuenotmodified) {
synchronized(this) {
wait()
}
}
}
Option Two
class A {
public void methodOne() {
modifyvalue
synchronized(this) {
notifyAll()
}
}
public void methodTwo() {
while (valuenotmodified) {
synchronized(this) {
wait()
}
}
}
and why?
© Stack Overflow or respective owner