Java Oncurrent?取决于同步的内容。如果您执行同步(此),则应用完全相同的规则。 public class Test { public synchronized void m1() { try { Thread.sleep(20
Java Oncurrent?取决于同步的内容。如果您执行同步(此),则应用完全相同的规则。 public class Test { public synchronized void m1() { try { Thread.sleep(20,java,multithreading,synchronized,Java,Multithreading,Synchronized,Oncurrent?取决于同步的内容。如果您执行同步(此),则应用完全相同的规则。 public class Test { public synchronized void m1() { try { Thread.sleep(2000); } catch (InterruptedException ie) {} } public synchronized void m2() { try { Thread.sleep(20
Oncurrent?取决于同步的内容。如果您执行同步(此),则应用完全相同的规则。
public class Test {
public synchronized void m1() {
try { Thread.sleep(2000); }
catch (InterruptedException ie) {}
}
public synchronized void m2() {
try { Thread.sleep(2000); }
catch (InterruptedException ie) {}
}
public static void main(String[] args) throws InterruptedException {
final Test t = new Test();
Thread t1 = new Thread() { public void run() { t.m1(); } };
Thread t2 = new Thread() { public void run() { t.m2(); } };
t1.start();
Thread.sleep(500);
t2.start();
Thread.sleep(500);
System.out.println(t2.getState());
}
}
BLOCKED
// Thread 1
A a1 = new A();
a1.m1();
// Thread 2
A a2 = new A();
a2.m2()