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. … Read more

“implements Runnable” vs “extends Thread” in Java

From what time I’ve spent with threads in Java, I’ve found these two ways to write threads: With implements Runnable: public class MyRunnable implements Runnable { public void run() { //Code } } //Started with a “new Thread(new MyRunnable()).start()” call Or, with extends Thread: public class MyThread extends Thread { public MyThread() { super(“MyThread”); } … Read more