Clase Thread - docencia de la ETSIT-URJC
Clase Thread - docencia de la ETSIT-URJC
Clase Thread - docencia de la ETSIT-URJC
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Ejemplo<br />
El problema con el ejemplo anterior se reproduce<br />
cuando dos o más hilos acce<strong>de</strong>n a los métodos poner<br />
y quitar <strong>de</strong> forma <strong>de</strong>scontro<strong>la</strong>da.<br />
Debemos evitar que mientras un hilo intenta poner<br />
(quitar) el otro realice una operación que altere los<br />
datos.<br />
public c<strong>la</strong>ss Pi<strong>la</strong> {<br />
...<br />
...<br />
}<br />
public void poner(char c) {<br />
}<br />
synchronized (this) {<br />
data[idx] = c;<br />
idx++;<br />
}