Why my void run method cannot be execute?
Code :
public class MyRun implements Runnable{
int[] array = new int[5];
int index;
MyRun(int value, int index){
this.index = index;
array[index] = value;
}
}
//run() method to do operation
public void run(){
System.out.println("run()");
for(int count = 0; count < 5; count++)
System.out.println(array[count]);
}
}
and the main thread:
Code :
import java.util.concurrent.*;
public class satu {
public static void main(String[]args){
int[] array = {4,2,3,1,5};
int lowest = array[0], highest = array[0];
int pivot;
ExecutorService executor = Executors.newFixedThreadPool(1);
for(int index = 1; index < array.length; index++){
//mission: find highest n lowest
if(lowest > array[index])
lowest = array[index];
else if (highest < array[index])
highest = array[index];
}
pivot = array[lowest + (highest - lowest)/2];
for(int count = 0; count < array.length; count++){
Runnable task = new MyRun(array[count],count);
}
executor.shutdown();
while(!executor.isTerminated());
System.out.println("Finish");
}
}
Why my run() cant be execute? Please, please do help me..
Re: Why my void run method cannot be execute?
...when are you calling the run() method?
Re: Why my void run method cannot be execute?
You should submit the Runnable object to the ExecutorService, for example: