I have a Theadpool, that creates and makes a group of functions, I would like to stop, pause and resume this group of Theads with buttons, so I can see the results of the simulation. Here is the code:
void mysterious(){
// create a pool of threads, 10 max jobs will execute in parallel
/// start
ExecutorService threadPool = Executors.newFixedThreadPool(network.mobiles.size());
// submit jobs to be executing by the pool
for (int i=0; i<network.mobiles.size(); i++) {
// for (int i=0; i<1; i++) {
final int j = i ;
threadPool.submit(new Runnable() {
public void run() {
int value = 100 ;
for (int z=0; z<value; z++){
value++;
int x = (mobnod[j].getLocation().x) +7;
int y = (mobnod[j].getLocation().y) +7 ;
System.out.println("x="+x+" , y="+y);
double r = Math.random();
System.out.println(r);
if (r<0.25) x=x-5;
if (r>=0.25 && r<0.50) x=x+5;
if (r>=0.5 && r<0.75) y=y-5;
if (r>=0.75 && r<1.00) y=y+5;
System.out.println("x'="+x+" , y'="+y);
if ((0 < x && x<1300) || (0 <y && y <800)){
mobnod[j].setLocation(x-7, y-7);
network.mobiles.get(j).findClosestAP(network.nodes);
network.setConnections();
}
try {
threadPool.awaitTermination(1000, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
}
// once you've submitted your last job to the service it should be shut down
threadPool.shutdown();
// wait for the threads to finish if necessary
}
Help me please , Thanks :)