public class Foo implements Runnable {
private String mLock;
public void lockedMethod() {
......
synchronized (mLock) {
......
}
......
}
@Override
public void run() {
// TODO Auto-generated method stub
}
}
synchronized还可以用在类的方法前面,如下:
public class FooA implements Runnable {
public synchronized void lockedMethod() {......}
public synchronized void unlockedMethod() {......}
@Override
public void run() {
// TODO Auto-generated method stub
}
}