James 3 years ago
parent
commit
0237b76346
1 changed files with 10 additions and 16 deletions
  1. 10 16
      src/main/java/com/jfinal/kit/ScheduledKit.java

+ 10 - 16
src/main/java/com/jfinal/kit/ScheduledKit.java

@@ -81,14 +81,11 @@ public class ScheduledKit {
 	 * 任务添加 try catch ,避免 scheduleWithFixedDelay 方法在调度任务出现异常后会终止调度
  	 */
 	public static ScheduledFuture<?> scheduleWithFixedDelayWithTryCatch(Runnable task, long initialDelay, long delay, TimeUnit unit) {
-		return scheduleWithFixedDelay(new Runnable() {
-			@Override
-			public void run() {
-				try {
-					task.run();
-				} catch (Throwable t) {
-					Log.getLog(ScheduledKit.class).error(t.getMessage(), t);
-				}
+		return scheduleWithFixedDelay(() -> {
+			try {
+				task.run();
+			} catch (Throwable t) {
+				Log.getLog(ScheduledKit.class).error(t.getMessage(), t);
 			}
 		}, initialDelay, delay, unit);
 	}
@@ -108,14 +105,11 @@ public class ScheduledKit {
 	 * 任务添加 try catch ,避免 scheduleAtFixedRate 方法在调度任务出现异常后会终止调度
  	 */
 	public static ScheduledFuture<?> scheduleAtFixedRateWithTryCatch(Runnable task, long initialDelay, long period, TimeUnit unit) {
-		return scheduleAtFixedRate(new Runnable() {
-			@Override
-			public void run() {
-				try {
-					task.run();
-				} catch (Throwable t) {
-					Log.getLog(ScheduledKit.class).error(t.getMessage(), t);
-				}
+		return scheduleAtFixedRate(() -> {
+			try {
+				task.run();
+			} catch (Throwable t) {
+				Log.getLog(ScheduledKit.class).error(t.getMessage(), t);
 			}
 		}, initialDelay, period, unit);
 	}