while(data.hasNextInt()){ synchronized (Relay.this){ if(nextId==null) { nextId = data.nextInt(); inform(); } try { Relay.this.wait(); } catch (InterruptedException e) { } } } koniec=true; inform();