程式設計師的睡覺程式設計藝術
阿新 • • 發佈:2018-11-21
public class Test{ // 升序排序 public static List<Integer> sort(List<Integer> list) throws Exception { List<Integer> resultList = new ArrayList<>(); for (int i : list) { new Thread() { public void run() { try { Thread.sleep(i * 1000); resultList.add(i); } catch (Exception e) { e.printStackTrace(); } }; }.start(); } ; while (true) { if (Thread.activeCount() == 1) { break; } Thread.sleep(100); } return resultList; } // 獲取一天後的時間 public static Date getNextDate() throws Exception { Thread.sleep(24 * 3600 * 1000); return new Date(); } }