Like the title, given 2 arrays int[] a, int[] b shared by two Threads each of which rearrange the elements of the two arrays in a way that each element of the first array is <= of the corrispondent element of the second array a[i] <= b[i] the output seems to be always correct without the needs of synchronization
public class MyClass {
    int[] a = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
    int[] b = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    class MyThread extends Thread {
        public void run() {
                for (int i = 0; i < a.length; i++) {
                    if (a[i] > b[i]) {
                        int temp = b[i];
                        b[i] = a[i];
                        a[i] = temp;
                    }
                }
        }
    }
    public static void main(String[] args) {
        MyClass myClass = new MyClass();
        MyThread t1 = myClass.new MyThread();
        MyThread t2 = myClass.new MyThread();
        t1.start();
        t2.start();
        while (t1.isAlive() | t2.isAlive()) {
            System.out.println("waiting");
        }
        System.out.println(Arrays.toString(myClass.a));
        System.out.println(Arrays.toString(myClass.b));
    }
}
Here is the output i'm getting (on multiple runs) should i consider this only luck or is there somethig i'm missing?
a = [0, 1, 2, 3, 4, 4, 3, 2, 1, 0]
b = [9, 8, 7, 6, 5, 5, 6, 7, 8, 9]
 
     
     
     
    