multithreading - Synchronizing two methods in Java -
multithreading - Synchronizing two methods in Java -
i have class one:
public class iclass{ public void draw(){...}; //is called periodically rendering thread public void foo(){...}; //is called asynchronously thread(it ontouchevent() method example) }
i want foo() method wait until draw method finished , vice versa. how can in java?
regards
make methods synchronized.
public synchronized void draw() { system.out.println("draw"); } public synchronized void foo() { system.out.println("foo"); }
or synchronize on same object.
private static final object syncobj = new object(); public void draw() { synchronized (syncobj) { system.out.println("draw"); } } public void foo() { synchronized (syncobj) { system.out.println("foo"); } }
java multithreading synchronization
Comments
Post a Comment