Сколько будет выполняться данная программа:
public class Main {
public static void main(String... args) {
Test test = new Test();
new Thread(test::a).start();
new Thread(test::a).start();
new Thread(test::b).start();
new Thread(test::b).start();
}
public static void sleep(long millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
Если Test имеет следующую реализацию:
class Test {
public synchronized void a() {
System.out.println("test a");
Main.sleep(10000);
}
public synchronized void b() {
System.out.println("test b");
Main.sleep(10000);
}
}
class Test {
public void a() {
System.out.println("test a");
Main.sleep(10000);
}
public void b() {
System.out.println("test b");
Main.sleep(10000);
}
}
class Test {
public void a() {
synchronized ("test a") {
System.out.println("test a");
Main.sleep(10000);
}
}
public void b() {
synchronized ("test b") {
System.out.println("test b");
Main.sleep(10000);
}
}
}
class Test {
public void a() {
synchronized ("test") {
System.out.println("test a");
Main.sleep(10000);
}
}
public void b() {
synchronized ("test") {
System.out.println("test b");
Main.sleep(10000);
}
}
}