mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-19 12:16:48 +00:00
perf[runnable]: 使用Runnable函数式编程接口
This commit is contained in:
1 parent
a637db260a
commit
c4cdf272eb
42 files changed
+105
-142
No files matched your search
@@ -34,7 +34,7 @@ import java.lang.reflect.Modifier;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
public class SchedulerContext implements ApplicationListener<ApplicationContextEvent>, Ordered {
|
||||
|
||||
@@ -72,7 +72,7 @@ public abstract class SchedulerBus {
|
||||
|
||||
public static class SchedulerThreadFactory implements ThreadFactory {
|
||||
|
||||
private int poolNumber;
|
||||
private final int poolNumber;
|
||||
private final AtomicInteger threadNumber = new AtomicInteger(1);
|
||||
private final ThreadGroup group;
|
||||
|
||||
@@ -166,24 +166,24 @@ public abstract class SchedulerBus {
|
||||
/**
|
||||
* 不断执行的周期循环任务
|
||||
*/
|
||||
public static void scheduleAtFixedRate(SafeRunnable runnable, long period, TimeUnit unit) {
|
||||
public static void scheduleAtFixedRate(Runnable runnable, long period, TimeUnit unit) {
|
||||
if (SchedulerContext.isStop()) {
|
||||
return;
|
||||
}
|
||||
|
||||
executor.scheduleAtFixedRate(runnable, 0, period, unit);
|
||||
executor.scheduleAtFixedRate(SafeRunnable.valueOf(runnable), 0, period, unit);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 固定延迟执行的任务
|
||||
*/
|
||||
public static void schedule(SafeRunnable runnable, long delay, TimeUnit unit) {
|
||||
public static void schedule(Runnable runnable, long delay, TimeUnit unit) {
|
||||
if (SchedulerContext.isStop()) {
|
||||
return;
|
||||
}
|
||||
|
||||
executor.schedule(runnable, delay, unit);
|
||||
executor.schedule(SafeRunnable.valueOf(runnable), delay, unit);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,12 +18,12 @@ import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
public class StopWatch {
|
||||
|
||||
private long startTime = TimeUtils.currentTimeMillis();
|
||||
private final long startTime = TimeUtils.currentTimeMillis();
|
||||
|
||||
public long cost() {
|
||||
return TimeUtils.currentTimeMillis() - startTime;
|
||||
|
||||
@@ -16,7 +16,7 @@ package com.zfoo.scheduler.model.anno;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
@Documented
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
public abstract class EnhanceUtils {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
package com.zfoo.scheduler.model.vo;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
public interface IScheduler {
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.lang.reflect.Method;
|
||||
/**
|
||||
* 动态代理被Scheduler注解标注的方法,为了避免反射最终会用javassist字节码增强的方法去代理ReflectScheduler
|
||||
*
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
public class ReflectScheduler implements IScheduler {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
package com.zfoo.scheduler.model.vo;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
public class RunnableScheduler implements IScheduler {
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
public class SchedulerDefinition {
|
||||
|
||||
@@ -16,7 +16,7 @@ package com.zfoo.scheduler.schema;
|
||||
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
public class NamespaceHandler extends NamespaceHandlerSupport {
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.w3c.dom.Element;
|
||||
* 从而可以得出结论:在基于zfoo的SpringBoot工程中,由于压根不解析xml对象,注册bean也是通过@Configuration配置类注册bean的,
|
||||
* 因此这些实现BeanDefinitionParser接口的parse方法是都不会执行的。
|
||||
*
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
public class SchedulerDefinitionParser implements BeanDefinitionParser {
|
||||
|
||||
@@ -26,7 +26,7 @@ import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
public abstract class TimeUtils {
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
* cron(译为克龙)代表100万年,是英文单词中最大的时间单位。
|
||||
* google(译为古戈尔)代表10的100次方,足够穷尽宇宙万物
|
||||
*
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
@Component
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.time.temporal.TemporalAdjusters;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author jaysunxiao
|
||||
* @author godotg
|
||||
* @version 3.0
|
||||
*/
|
||||
public class TimeUtilsTest {
|
||||
|
||||
Reference in new issue
Block a user