Академический Документы
Профессиональный Документы
Культура Документы
3 {
4 if (nombre != null)
5 setName(nombre);
6 start(); //el hilo ejecuta su propio método run
7 }
8
9 public ContadorAdelante() { this(null); } // constructor
10 public voidrun()
11 {
12 for (inti=1; i<=1000; i++)
13 System.out.print(getName() + " "+i+"\r");
14 System.out.println();
15 }
16 }
1 public classTestHilo
2 {
3 public static void main(String []args)
4 {
5 ContadorAdelante cuentaAdelante = new
6 ContadorAdelante("Contador+");
7 }
1Tomado de Guión de clases Programación III. Inga. Patricia Estrada. Universidad de El Salvador. Año 2006.
8 }
class hilos{
public static void main(String args[]){
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
pulso h1=new pulso(Thread.NORM_PRIORITY+2);
pulso h2=new pulso(Thread.NORM_PRIORITY-2);
h1.start();
h2.start();
try{Thread.sleep(10000);}
catch(Exception e){}
h1.stop();
h2.stop();