i have been trying to runout the multithread but i get the error can any one help me , i have been changing the hole lot but i havent found the way to sort out the problem: "No enclosing instance of type programa4 is accessible. Must qualify the allocation with an enclosing instance of type programa4 (e.g. x.new A() where x is an instance of programa4)." Thanks for all.
public class programa4 {
public static void main(String[] args) {
int t=Integer.parseInt(args[0]);
int x=1;
String z=args[1];
while(x<=t){
System.out.println("Iniciando hilo "+x);
new hilo(z).start();
x=x+1;
}
}
class hilo extends Thread{
int num;
String z;
hilo(String z){
this.num=Integer.parseInt(z);
}
public void run() {
int t=1;
while(t<=num){
System.out.println("Generando iteracion: "+ t);
double x=Math.random()*10;
System.out.println("Esperando "+ x +" segundos");
try {
Thread.sleep((long)x*1000);
System.out.println("Iteracion terminada");
} catch (InterruptedException e) {
System.out.println("Se interrumpio.");
}
t=t+1;
}
System.out.println("Terminado hilo.");
}
}
}