@Slf4j(topic = "SimpleDateFormat") publicclassSimpleDateFormatDemo{ privatestaticfinal SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); publicstaticvoidmain(String[] args){ String dateStr = "2001-09-11 00:00:00.000"; for (int i = 0; i < 10; i++) { new Thread(() -> { try { log.debug(SDF.parse(dateStr).toString()); } catch (ParseException e) { e.printStackTrace(); } }).start(); } } }
结果:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
java.lang.NumberFormatException: multiple points at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1890) at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110) at java.lang.Double.parseDouble(Double.java:538) at java.text.DigitList.getDouble(DigitList.java:169) at java.text.DecimalFormat.parse(DecimalFormat.java:2089) at java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:1869) at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1514) at java.text.DateFormat.parse(DateFormat.java:364) at top.parak.immutable.SimpleDateFormatDemo.lambda$main$0(SimpleDateFormatDemo.java:22) at java.lang.Thread.run(Thread.java:748) 2021-04-2911:30:23.116 [Thread-2] DEBUG SimpleDateFormat - Sun Sep 1100:00:00 CST 1121 2021-04-2911:30:23.117 [Thread-9] DEBUG SimpleDateFormat - Sun Sep 1100:00:00 CST 1121 2021-04-2911:30:23.117 [Thread-5] DEBUG SimpleDateFormat - Tue Sep 1100:00:00 CST 2001
/** * 初始化连接池 */ publicPool(int pollSize){ this.poolSize = pollSize; connections = new Connection[pollSize]; states = new AtomicIntegerArray(newint[pollSize]); for (int i = 0; i < pollSize; i++) { connections[i] = new ParaKConnection("连接" + (i + 1)); } }
/** * 获取一个连接 */ public Connection get(){ while (true) { // 查看是否有空闲连接 for (int i = 0; i < poolSize; i++) { if (states.get(i) == 0) { if (states.compareAndSet(i, 0, 1)) { log.debug("get {}", connections[i]); return connections[i]; } } } // 没有空闲连接则等待 synchronized (this) { try { log.debug("wait..."); this.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } } }
/** * 释放一个连接 */ publicvoidfree(Connection connection){ for (int i = 0; i < poolSize; i++) { if (connections[i] == connection) { states.set(i, 0); synchronized (this) { log.debug("free {}", connection); this.notifyAll(); } break; } } } }