import java.util.Arrays;
import java.util.concurrent.ForkJoinPool;

public class ForkJoinSorter {
    public static void sort(int[][] matrix) {
        ForkJoinPool pool = new ForkJoinPool();
        Integer[] indices = new Integer[matrix[0].length];
        for (int i = 0; i < indices.length; i++)
            indices[i] = i;

        Arrays.sort(indices, (a, b) -> Integer.compare(matrix[0][b], matrix[0][a]));

        int[][] sorted = new int[matrix.length][matrix[0].length];
        pool.invoke(new ForkJoinTask(matrix, sorted, indices, 0, indices.length));
        pool.shutdown();

        for (int i = 0; i < matrix.length; i++)
            System.arraycopy(sorted[i], 0, matrix[i], 0, indices.length);
    }
}
