このように、2つの異なるクラスに2つのメソッドがあります
public class ClassX implements Runnable {
public void methodAandB() {
for(int i=0;i<10;i++) {
System.out.println("This is A and B ");
}
}
@Override
public void run() {
methodAandB();
}
}
public class ClassY implements Runnable {
public void methodAorB() {
for(int i=0;i<10;i++) {
System.out.println("This is A or B");
}
}
@Override
public void run() {
methodAorB(a);
}
}
スレッドt1が を呼び出してmethodAandB()
います。
スレッドt2が を呼び出してmethodAorB()
います。
メソッド内のループを繰り返すたびに、これら 2 つのスレッドを切り替えることはできますか?
次のような出力を取得したい:
こちらはAとB
これはAかB
こちらはAとB
これはAかB
こちらはAとB
これはAかB
こちらはAとB
これはAかB