这两个代码块的行为是否相同?您可以假设这些运行方法是从线程调用的。
public synchronized void run() {
System.out.println("A thread is running.");
}
或者
static Object syncObject = new Object();
public void run() {
synchronized(syncObject) {
System.out.println("A thread is running.");
}
}