If I synchronized two methods on the same class, can they run simultaneously?

If I synchronized two methods on the same class, can they run simultaneously on the same object? For example:

class A {
    public synchronized void methodA() {
        //method A
    }

    public synchronized void methodB() {
        // method B
    }
}

I know that I can’t run methodA() twice on same object in two different threads. same thing in methodB().

But can I run methodB() on different thread while methodA() is still running? (same object)

12 Answers
12

Leave a Comment