1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| public class SimpleDateFormatTest {
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static void main(String[] args) { final CountDownLatch latch = new CountDownLatch(1); List<String> date = Arrays.asList("2021-01-01 12:12:12", "2021-01-02 11:11:11", "2021-01-11 09:09:09"); IntStream.range(1, 10).forEach(v -> { new Thread(() -> { try { latch.await(); } catch (InterruptedException e) { e.printStackTrace(); } IntStream.range(0, 10).forEach(i -> { try { System.out.println(DATE_FORMAT.parse(date.get(i % date.size()))); Thread.sleep(100); } catch (InterruptedException | ParseException e) { e.printStackTrace(); } }); }).start(); }); latch.countDown(); } }
|