Clase Thread - docencia de la ETSIT-URJC
Clase Thread - docencia de la ETSIT-URJC
Clase Thread - docencia de la ETSIT-URJC
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Extendiendo <strong>la</strong> c<strong>la</strong>se <strong>Thread</strong><br />
public c<strong>la</strong>ss Nombre extends <strong>Thread</strong> {<br />
public Nombre ( String nombre ){<br />
super( nombre );<br />
}<br />
public void run() {<br />
while( true ) {<br />
System.out.println<br />
(System.currentTimeMillis() + ": " + getName());<br />
}<br />
}<br />
}<br />
public c<strong>la</strong>ss Prueba {<br />
public static void main( String[] args ) {<br />
Nombre n1 = new Nombre ( "Jaime" );<br />
Nombre n2 = new Nombre ( " Lo<strong>la</strong>" );<br />
n1.start();<br />
n2.start();<br />
}<br />
}<br />
<strong>Thread</strong> principal<br />
<strong>Thread</strong> Jaime<br />
<strong>Thread</strong> Lo<strong>la</strong><br />
$ java Prueba<br />
1177437609460: Jaime<br />
1177437609460: Lo<strong>la</strong><br />
1177437609461: Jaime<br />
1177437609461: Lo<strong>la</strong><br />
1177437609461: Jaime<br />
1177437609461: Lo<strong>la</strong><br />
1177437609461: Jaime<br />
1177437609461: Jaime<br />
1177437609461: Jaime<br />
1177437609461: Jaime<br />
1177437609461: Jaime<br />
1177437609461: Jaime<br />
1177437609461: Jaime<br />
1177437609461: Jaime<br />
1177437609461: Jaime<br />
1177437609461: Jaime<br />
1177437609461: Jaime<br />
1177437609461: Jaime<br />
1177437609461: Lo<strong>la</strong><br />
1177437609461: Jaime