15.05.2013 Views

Clase Thread - docencia de la ETSIT-URJC

Clase Thread - docencia de la ETSIT-URJC

Clase Thread - docencia de la ETSIT-URJC

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Definición <strong>de</strong> threads<br />

En Java se pue<strong>de</strong> <strong>de</strong>finir y crear un<br />

thread <strong>de</strong> 2 formas:<br />

• Extendiendo <strong>la</strong> c<strong>la</strong>se <strong>Thread</strong><br />

• Se <strong>de</strong>c<strong>la</strong>ra una subc<strong>la</strong>se <strong>de</strong> <strong>Thread</strong> y se<br />

reemp<strong>la</strong>za su método run()<br />

• Luego se crea una instancia <strong>de</strong> <strong>la</strong> subc<strong>la</strong>se<br />

Implementando <strong>la</strong> interfaz Runnable<br />

• Se <strong>de</strong>c<strong>la</strong>ra una c<strong>la</strong>se que implementa <strong>la</strong><br />

interfaz Runnable, <strong>de</strong>finiendo el método<br />

run()<br />

• Luego se crea una instancia <strong>de</strong> esta c<strong>la</strong>se y se<br />

le pasa al constructor <strong>Thread</strong>()

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!