public class Player implements Runnable { private Integer choice; private final Object lockChoice = new Object(); @Override public void run() { while (true) { synchronized (lockChoice) { while (choice != null) { // alternativ bspw. mit zusätzlichem boolean try { lockChoice.wait(); } catch (InterruptedException e) { // -> soll sich beenden return; } } choice = new java.util.Random().nextInt(3); lockChoice.notify(); } } } public int getChoice() throws InterruptedException { synchronized (lockChoice) { while (choice == null) // alternativ bspw. mit zusätzlichem boolean lockChoice.wait(); int c = this.choice; choice = null; lockChoice.notify(); return c; } } public static String choiceToString(int choice) { // war nicht gefordert! switch (choice) { case 0: return "Schere"; case 1: return "Stein"; case 2: return "Papier"; default: return "Nichts"; } } }