I have a list of Script that i want to execute them in parallel, i already find this way in [Creating dynamic number of threads concurrently](https://stackoverflow.com/a/10092317/5558072), so i use this piece of code here :

```
private int i;//<---------------------------------(1)
private String[] listScript = {"Script1", "Script2", "Script3", "Script4"};

private void executeQueries() throws InterruptedException {

    ExecutorService threadPool = Executors.newFixedThreadPool(listScript.length);
    // submit jobs to be executing by the pool
    for (i = 0; i < listScript.length; i++) {
        threadPool.submit(new Runnable() {
            @Override
            public void run() {
                executeQuerie();
            }
        });
        Thread.sleep(500);//<---------------------(2)
    }
    // 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
    threadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);

}

private void executeQuerie() {
    //execute scripts action
    System.out.println(listScript[i]);
}

```

I'm really not happy with this code, i will explain a little my code so you can understand more :

(1). I use this `i` variable outside the method so i can know which script i should to execute  

 (2). I use `Thread.sleep(500);` to make sure that i execute the right script, without this i can execute the same script multiple time for example it can gives me:

```
Script1
Script1
Script2
Script2

```

My question is : how can i make sure that my scripts executed safely in parallel, should i improve this piece of code, or do you have any other safe way?