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.
<strong>Thread</strong>.sleep()<br />
public c<strong>la</strong>ss Nombre extends <strong>Thread</strong> {<br />
int periodo;<br />
public Nombre ( String nombre, int periodo ){<br />
super( nombre );<br />
this.periodo = periodo;<br />
}<br />
public void run() {<br />
while( true ) {<br />
System.out.println<br />
(System.currentTimeMillis() + ": " + getName());<br />
try { <strong>Thread</strong>.sleep ( periodo ); }<br />
catch (InterruptedException e) {return ;}<br />
}<br />
}<br />
}<br />
public c<strong>la</strong>ss Prueba {<br />
public static void main( String[] args ) {<br />
Nombre n1 = new Nombre ( "Jaime”, 500 );<br />
Nombre n2 = new Nombre ( " Lo<strong>la</strong>”, 100 );<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 />
1177448963165: Jaime<br />
1177448963165: Lo<strong>la</strong><br />
1177448963265: Lo<strong>la</strong><br />
1177448963366: Lo<strong>la</strong><br />
1177448963466: Lo<strong>la</strong><br />
1177448963566: Lo<strong>la</strong><br />
1177448963665: Jaime<br />
1177448963667: Lo<strong>la</strong><br />
1177448963767: Lo<strong>la</strong><br />
1177448963867: Lo<strong>la</strong><br />
1177448963967: Lo<strong>la</strong><br />
1177448964068: Lo<strong>la</strong><br />
1177448964166: Jaime<br />
1177448964168: Lo<strong>la</strong><br />
1177448964268: Lo<strong>la</strong><br />
1177448964369: Lo<strong>la</strong><br />
1177448964469: Lo<strong>la</strong><br />
1177448964569: Lo<strong>la</strong>