public class SleepSort {
public static void main(String[] args) {
int[] a = { 42, 51, 15, 24, 1, 69, 12, 8, 34, 10 };
for (int i : a) {
ThreadPrint t = new ThreadPrint(i);
t.start();
}
}
}
class ThreadPrint extends java.lang.Thread {
private int i;
public ThreadPrint(int pi) {
i = pi;
}
public void run() {
synchronized (this) {
try {
wait(i);
notifyAll();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.print(i + ",");
}
}
}