I currently have some problems to understand why in some cases, parallelization in Java seems infficient. In the following code, I build 4 identical tasks that are executed
The clue is that you are calling Math.random which uses a single global instance of Random. So, all your 4 threads compete for the one resource.
Using a thread local Random object will make your execution really parallel:
Random random = new Random();
double[] array = new double[10000000];
for (int i = 0; i < array.length; i++) {
array[i] = Math.tanh(random.nextDouble());
}