The code needs the while true to long quite a long time. Only rarely the i and j values are unequal.
k values are never unequal.
If you want a shorter output, you have to put yield-calls into the method to give other threads a chance.
produces
i
j
i
j
i
j
i
j
i
j
i
j
i
j
i
j
i
j
on my system.
Also here the k values are never unqual.
But you have forgotten something:
Quote your sources, please.
Yours,
Bu.