tianyun 3 éve
szülő
commit
03293208b0

+ 3 - 6
springboot-main/src/main/java/com/alvin/Application.java

@@ -1,13 +1,10 @@
 package com.alvin;
 
-import org.springframework.util.Assert;
-import org.springframework.util.StopWatch;
+
+import com.alvin.util.NumberUtil;
 
 public class Application {
     public static void main(String[] args) {
-        //Assert.isTrue("123".matches("^[a-zA-Z][0-9a-zA-Z_]*$"),"表名不符合规范,必须以英文开头,不能带有特殊字符");
-        Assert.isTrue("A1_23".matches("^[a-zA-Z][0-9a-zA-Z_]*$"),"表名不符合规范,必须以英文开头,不能带有特殊字符");
-        //Assert.isTrue("A1_*23".matches("^[a-zA-Z][0-9a-zA-Z_]*$"),"表名不符合规范,必须以英文开头,不能带有特殊字符");
-        Assert.isTrue("_A1_*23".matches("^[a-zA-Z][0-9a-zA-Z_]*$"),"表名不符合规范,必须以英文开头,不能带有特殊字符");
+
     }
 }

+ 37 - 0
springboot-main/src/main/java/com/alvin/util/DateUtil.java

@@ -94,6 +94,43 @@ public class DateUtil {
         return LocalDateTime.of(lastDayOfThisMonth(), LocalTime.MAX);
     }
 
+    /**
+     * 将毫秒转换为  时分秒,用于时间间隔的计算
+     *
+     * @param ms 毫秒数
+     * @return {@link String}
+     */
+    public static String formatTime(Long ms) {
+        Integer ss = 1000;
+        Integer mi = ss * 60;
+        Integer hh = mi * 60;
+        Integer dd = hh * 24;
+
+        Long day = ms / dd;
+        Long hour = (ms - day * dd) / hh;
+        Long minute = (ms - day * dd - hour * hh) / mi;
+        Long second = (ms - day * dd - hour * hh - minute * mi) / ss;
+        Long milliSecond = ms - day * dd - hour * hh - minute * mi - second * ss;
+
+        StringBuffer sb = new StringBuffer();
+        if(day > 0) {
+            sb.append(day+" 天 ");
+        }
+        if(hour > 0) {
+            sb.append(hour+" 小时 ");
+        }
+        if(minute > 0) {
+            sb.append(minute+" 分 ");
+        }
+        if(second > 0) {
+            sb.append(second+" 秒 ");
+        }
+        if(milliSecond > 0) {
+            sb.append(milliSecond+" 毫秒");
+        }
+        return sb.toString();
+    }
+
     public static void main(String[] args) {
         System.out.println(DateUtil.getEpochMilli());
         System.out.println(DateUtil.getEpochSecond());

+ 15 - 0
springboot-main/src/main/java/com/alvin/util/NumberUtil.java

@@ -0,0 +1,15 @@
+package com.alvin.util;
+
+public class NumberUtil {
+    public static Float toFloat(Double doubleValue) {
+        return doubleValue == null ? null : doubleValue.floatValue();
+    }
+
+    public static Float toFloat(double doubleValue) {
+        return (float) doubleValue;
+    }
+
+    public static Float toString(double doubleValue) {
+        return (float) doubleValue;
+    }
+}

+ 29 - 0
springboot-main/src/main/java/com/alvin/util/StopWatch.java

@@ -0,0 +1,29 @@
+package com.alvin.util;
+
+class StopWatch {
+    private String name = "";
+    private long startTime;
+
+    public StopWatch() {
+        startTime = System.currentTimeMillis();
+    }
+
+    public StopWatch(String name) {
+        this();
+        this.name = name;
+    }
+
+    public String stop() {
+        long endTime = System.currentTimeMillis();
+        long spendTime = endTime - this.startTime;
+        String s = DateUtil.formatTime(spendTime);
+        System.out.println(this.name + " 用时:" + s);
+        return s;
+    }
+
+    public static void main(String[] args) throws InterruptedException {
+        StopWatch stopWatch = new StopWatch("A");
+        Thread.sleep(100);
+        stopWatch.stop();
+    }
+}

+ 14 - 3
test1/src/main/java/tmp.java

@@ -1,10 +1,21 @@
 import java.nio.file.Files;
 import java.util.BitSet;
+import java.util.concurrent.*;
 
 public class tmp {
     public static void main(String[] args) throws InterruptedException {
-        while (true) {
-            Math.pow(3, 1000);
-        }
+        ThreadPoolExecutor executor = new ThreadPoolExecutor(10,
+                20,
+                60L,
+                TimeUnit.SECONDS,
+                new LinkedBlockingQueue<Runnable>(10),
+                Executors.defaultThreadFactory(),
+                new RejectedExecutionHandler() {
+                    @Override
+                    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
+                        System.out.println(r.toString() + " is discard");
+                    }
+                }
+        );
     }
 }