import java.util.Arrays;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class ThreadPoolSorter {
    public static void sort(int[][] matrix) throws InterruptedException {
        int cols = matrix[0].length;
        Integer[] indices = new Integer[cols];
        for (int i = 0; i < cols; i++)
            indices[i] = i;

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

        ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
        int[][] sorted = new int[matrix.length][cols];

        for (int i = 0; i < cols; i++) {
            final int colIndex = i;
            executor.submit(() -> {
                for (int row = 0; row < matrix.length; row++) {
                    sorted[row][colIndex] = matrix[row][indices[colIndex]];
                }
            });
        }

        executor.shutdown();
        executor.awaitTermination(1, TimeUnit.HOURS);

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