@Override public void run() { boolean hecho = false; synchronized (sb) { // Obliga a pasar por aqui, de 1 en 1 try { while (!hecho) { if (turno.getTurno() == id) { sb.append(text); System.out.println("hilo " + id + sb.toString()); turno.setTurno(++id); hecho = true; sb.notifyAll(); } else { sb.wait(); } } } catch (Exception ex) { } out.append("hello world " + id + sb.toString() + "\n"); } }