mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-24 18:04:54 +08:00
remove TimeInterval
This commit is contained in:
parent
f94da98a20
commit
2c0194d86d
@ -25,6 +25,7 @@ import cn.hutool.core.convert.impl.TimeZoneConverter;
|
||||
import cn.hutool.core.convert.impl.URIConverter;
|
||||
import cn.hutool.core.convert.impl.URLConverter;
|
||||
import cn.hutool.core.convert.impl.UUIDConverter;
|
||||
import cn.hutool.core.convert.impl.ZoneIdConverter;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.lang.Opt;
|
||||
import cn.hutool.core.reflect.ClassUtil;
|
||||
@ -47,6 +48,7 @@ import java.time.LocalTime;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.OffsetTime;
|
||||
import java.time.Period;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
import java.util.Calendar;
|
||||
@ -211,6 +213,7 @@ public class RegisterConverter implements Converter, Serializable {
|
||||
// 其它类型
|
||||
defaultConverterMap.put(Class.class, new ClassConverter());
|
||||
defaultConverterMap.put(TimeZone.class, new TimeZoneConverter());
|
||||
defaultConverterMap.put(ZoneId.class, new ZoneIdConverter());
|
||||
defaultConverterMap.put(Locale.class, new LocaleConverter());
|
||||
defaultConverterMap.put(Charset.class, new CharsetConverter());
|
||||
defaultConverterMap.put(Path.class, new PathConverter());
|
||||
|
@ -6,10 +6,12 @@ import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.Month;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.OffsetTime;
|
||||
import java.time.ZoneId;
|
||||
@ -133,6 +135,12 @@ public class TemporalAccessorConverter extends AbstractConverter {
|
||||
* @return java.time中的对象
|
||||
*/
|
||||
private TemporalAccessor parseFromLong(final Class<?> targetClass, final Long time) {
|
||||
if(targetClass == Month.class){
|
||||
return Month.of(Math.toIntExact(time));
|
||||
} else if(targetClass == DayOfWeek.class){
|
||||
return DayOfWeek.of(Math.toIntExact(time));
|
||||
}
|
||||
|
||||
return parseFromInstant(targetClass, Instant.ofEpochMilli(time), null);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
package cn.hutool.core.convert.impl;
|
||||
|
||||
import cn.hutool.core.convert.AbstractConverter;
|
||||
import cn.hutool.core.date.ZoneUtil;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
@ -14,6 +16,9 @@ public class TimeZoneConverter extends AbstractConverter{
|
||||
|
||||
@Override
|
||||
protected TimeZone convertInternal(final Class<?> targetClass, final Object value) {
|
||||
if(value instanceof ZoneId){
|
||||
return ZoneUtil.toTimeZone((ZoneId) value);
|
||||
}
|
||||
return TimeZone.getTimeZone(convertToStr(value));
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,25 @@
|
||||
package cn.hutool.core.convert.impl;
|
||||
|
||||
import cn.hutool.core.convert.AbstractConverter;
|
||||
import cn.hutool.core.date.ZoneUtil;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* {@link ZoneId}转换器
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
public class ZoneIdConverter extends AbstractConverter {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
protected ZoneId convertInternal(final Class<?> targetClass, final Object value) {
|
||||
if (value instanceof TimeZone) {
|
||||
return ZoneUtil.toZoneId((TimeZone) value);
|
||||
}
|
||||
return ZoneId.of(convertToStr(value));
|
||||
}
|
||||
|
||||
}
|
@ -1455,29 +1455,6 @@ public class DateUtil extends CalendarUtil {
|
||||
return System.currentTimeMillis() - preTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计时器<br>
|
||||
* 计算某个过程花费的时间,精确到毫秒
|
||||
*
|
||||
* @return Timer
|
||||
*/
|
||||
public static TimeInterval timer() {
|
||||
return new TimeInterval();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 计时器<br>
|
||||
* 计算某个过程花费的时间,精确到毫秒
|
||||
*
|
||||
* @param isNano 是否使用纳秒计数,false则使用毫秒
|
||||
* @return Timer
|
||||
* @since 5.2.3
|
||||
*/
|
||||
public static TimeInterval timer(final boolean isNano) {
|
||||
return new TimeInterval(isNano);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建秒表{@link StopWatch},用于对代码块的执行时间计数
|
||||
* <p>
|
||||
|
@ -1,177 +0,0 @@
|
||||
package cn.hutool.core.date;
|
||||
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 分组计时器<br>
|
||||
* 计算某几个过程花费的时间,精确到毫秒或纳秒
|
||||
*
|
||||
* @author Looly
|
||||
* @since 5.5.2
|
||||
*/
|
||||
public class GroupTimeInterval implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final boolean isNano;
|
||||
protected final Map<String, Long> groupMap;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param isNano 是否使用纳秒计数,false则使用毫秒
|
||||
*/
|
||||
public GroupTimeInterval(final boolean isNano) {
|
||||
this.isNano = isNano;
|
||||
groupMap = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空所有定时记录
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public GroupTimeInterval clear(){
|
||||
this.groupMap.clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始计时并返回当前时间
|
||||
*
|
||||
* @param id 分组ID
|
||||
* @return 开始计时并返回当前时间
|
||||
*/
|
||||
public long start(final String id) {
|
||||
final long time = getTime();
|
||||
this.groupMap.put(id, time);
|
||||
return time;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重新计时并返回从开始到当前的持续时间秒<br>
|
||||
* 如果此分组下没有记录,则返回0;
|
||||
*
|
||||
* @param id 分组ID
|
||||
* @return 重新计时并返回从开始到当前的持续时间
|
||||
*/
|
||||
public long intervalRestart(final String id) {
|
||||
final long now = getTime();
|
||||
return now - ObjUtil.defaultIfNull(this.groupMap.put(id, now), now);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------- Interval
|
||||
|
||||
/**
|
||||
* 从开始到当前的间隔时间(毫秒数)<br>
|
||||
* 如果使用纳秒计时,返回纳秒差,否则返回毫秒差<br>
|
||||
* 如果分组下没有开始时间,返回{@code null}
|
||||
*
|
||||
* @param id 分组ID
|
||||
* @return 从开始到当前的间隔时间(毫秒数)
|
||||
*/
|
||||
public long interval(final String id) {
|
||||
final Long lastTime = this.groupMap.get(id);
|
||||
if (null == lastTime) {
|
||||
return 0;
|
||||
}
|
||||
return getTime() - lastTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从开始到当前的间隔时间
|
||||
*
|
||||
* @param id 分组ID
|
||||
* @param dateUnit 时间单位
|
||||
* @return 从开始到当前的间隔时间(毫秒数)
|
||||
*/
|
||||
public long interval(final String id, final DateUnit dateUnit) {
|
||||
final long intervalMs = isNano ? interval(id) / 1000000L : interval(id);
|
||||
if (DateUnit.MS == dateUnit) {
|
||||
return intervalMs;
|
||||
}
|
||||
return intervalMs / dateUnit.getMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* 从开始到当前的间隔时间(毫秒数)
|
||||
*
|
||||
* @param id 分组ID
|
||||
* @return 从开始到当前的间隔时间(毫秒数)
|
||||
*/
|
||||
public long intervalMs(final String id) {
|
||||
return interval(id, DateUnit.MS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从开始到当前的间隔秒数,取绝对值
|
||||
*
|
||||
* @param id 分组ID
|
||||
* @return 从开始到当前的间隔秒数,取绝对值
|
||||
*/
|
||||
public long intervalSecond(final String id) {
|
||||
return interval(id, DateUnit.SECOND);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从开始到当前的间隔分钟数,取绝对值
|
||||
*
|
||||
* @param id 分组ID
|
||||
* @return 从开始到当前的间隔分钟数,取绝对值
|
||||
*/
|
||||
public long intervalMinute(final String id) {
|
||||
return interval(id, DateUnit.MINUTE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从开始到当前的间隔小时数,取绝对值
|
||||
*
|
||||
* @param id 分组ID
|
||||
* @return 从开始到当前的间隔小时数,取绝对值
|
||||
*/
|
||||
public long intervalHour(final String id) {
|
||||
return interval(id, DateUnit.HOUR);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从开始到当前的间隔天数,取绝对值
|
||||
*
|
||||
* @param id 分组ID
|
||||
* @return 从开始到当前的间隔天数,取绝对值
|
||||
*/
|
||||
public long intervalDay(final String id) {
|
||||
return interval(id, DateUnit.DAY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从开始到当前的间隔周数,取绝对值
|
||||
*
|
||||
* @param id 分组ID
|
||||
* @return 从开始到当前的间隔周数,取绝对值
|
||||
*/
|
||||
public long intervalWeek(final String id) {
|
||||
return interval(id, DateUnit.WEEK);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从开始到当前的间隔时间(毫秒数),返回XX天XX小时XX分XX秒XX毫秒
|
||||
*
|
||||
* @param id 分组ID
|
||||
* @return 从开始到当前的间隔时间(毫秒数)
|
||||
*/
|
||||
public String intervalPretty(final String id) {
|
||||
return DateUtil.formatBetween(intervalMs(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取时间的毫秒或纳秒数,纳秒非时间戳
|
||||
*
|
||||
* @return 时间
|
||||
*/
|
||||
private long getTime() {
|
||||
return this.isNano ? System.nanoTime() : System.currentTimeMillis();
|
||||
}
|
||||
}
|
@ -1,133 +0,0 @@
|
||||
package cn.hutool.core.date;
|
||||
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
/**
|
||||
* 计时器<br>
|
||||
* 计算某个过程花费的时间,精确到毫秒或纳秒
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
public class TimeInterval extends GroupTimeInterval {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final String DEFAULT_ID = StrUtil.EMPTY;
|
||||
|
||||
/**
|
||||
* 构造,默认使用毫秒计数
|
||||
*/
|
||||
public TimeInterval() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param isNano 是否使用纳秒计数,false则使用毫秒
|
||||
*/
|
||||
public TimeInterval(final boolean isNano) {
|
||||
super(isNano);
|
||||
start();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 开始计时并返回当前时间
|
||||
*/
|
||||
public long start() {
|
||||
return start(DEFAULT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 重新计时并返回从开始到当前的持续时间
|
||||
*/
|
||||
public long intervalRestart() {
|
||||
return intervalRestart(DEFAULT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重新开始计算时间(重置开始时间)
|
||||
*
|
||||
* @return this
|
||||
* @see #start()
|
||||
* @since 3.0.1
|
||||
*/
|
||||
public TimeInterval restart() {
|
||||
start(DEFAULT_ID);
|
||||
return this;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------- Interval
|
||||
|
||||
/**
|
||||
* 从开始到当前的间隔时间(毫秒数)<br>
|
||||
* 如果使用纳秒计时,返回纳秒差,否则返回毫秒差
|
||||
*
|
||||
* @return 从开始到当前的间隔时间(毫秒数)
|
||||
*/
|
||||
public long interval() {
|
||||
return interval(DEFAULT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从开始到当前的间隔时间(毫秒数),返回XX天XX小时XX分XX秒XX毫秒
|
||||
*
|
||||
* @return 从开始到当前的间隔时间(毫秒数)
|
||||
* @since 4.6.7
|
||||
*/
|
||||
public String intervalPretty() {
|
||||
return intervalPretty(DEFAULT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从开始到当前的间隔时间(毫秒数)
|
||||
*
|
||||
* @return 从开始到当前的间隔时间(毫秒数)
|
||||
*/
|
||||
public long intervalMs() {
|
||||
return intervalMs(DEFAULT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从开始到当前的间隔秒数,取绝对值
|
||||
*
|
||||
* @return 从开始到当前的间隔秒数,取绝对值
|
||||
*/
|
||||
public long intervalSecond() {
|
||||
return intervalSecond(DEFAULT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从开始到当前的间隔分钟数,取绝对值
|
||||
*
|
||||
* @return 从开始到当前的间隔分钟数,取绝对值
|
||||
*/
|
||||
public long intervalMinute() {
|
||||
return intervalMinute(DEFAULT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从开始到当前的间隔小时数,取绝对值
|
||||
*
|
||||
* @return 从开始到当前的间隔小时数,取绝对值
|
||||
*/
|
||||
public long intervalHour() {
|
||||
return intervalHour(DEFAULT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从开始到当前的间隔天数,取绝对值
|
||||
*
|
||||
* @return 从开始到当前的间隔天数,取绝对值
|
||||
*/
|
||||
public long intervalDay() {
|
||||
return intervalDay(DEFAULT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从开始到当前的间隔周数,取绝对值
|
||||
*
|
||||
* @return 从开始到当前的间隔周数,取绝对值
|
||||
*/
|
||||
public long intervalWeek() {
|
||||
return intervalWeek(DEFAULT_ID);
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package cn.hutool.core.thread;
|
||||
|
||||
import cn.hutool.core.date.TimeInterval;
|
||||
import cn.hutool.core.date.StopWatch;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
@ -24,7 +24,7 @@ import java.io.IOException;
|
||||
*/
|
||||
public class ConcurrencyTester implements Closeable {
|
||||
private final SyncFinisher sf;
|
||||
private final TimeInterval timeInterval;
|
||||
private final StopWatch timeInterval;
|
||||
private long interval;
|
||||
|
||||
/**
|
||||
@ -33,7 +33,7 @@ public class ConcurrencyTester implements Closeable {
|
||||
*/
|
||||
public ConcurrencyTester(final int threadSize) {
|
||||
this.sf = new SyncFinisher(threadSize);
|
||||
this.timeInterval = new TimeInterval();
|
||||
this.timeInterval = new StopWatch();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -52,7 +52,8 @@ public class ConcurrencyTester implements Closeable {
|
||||
.setBeginAtSameTime(true)
|
||||
.start();
|
||||
|
||||
this.interval = timeInterval.interval();
|
||||
timeInterval.stop();
|
||||
this.interval = timeInterval.getLastTaskTimeMillis();
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -69,7 +70,6 @@ public class ConcurrencyTester implements Closeable {
|
||||
*/
|
||||
public ConcurrencyTester reset(){
|
||||
this.sf.clearWorker();
|
||||
this.timeInterval.restart();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -313,19 +313,6 @@ public class DateUtilTest {
|
||||
Assert.assertEquals("31天1小时21分", formatBetween);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void timerTest() {
|
||||
final TimeInterval timer = DateUtil.timer();
|
||||
|
||||
// ---------------------------------
|
||||
// -------这是执行过程
|
||||
// ---------------------------------
|
||||
|
||||
timer.interval();// 花费毫秒数
|
||||
timer.intervalRestart();// 返回花费时间,并重置开始时间
|
||||
timer.intervalMinute();// 花费分钟数
|
||||
}
|
||||
|
||||
@Test
|
||||
public void currentTest() {
|
||||
final long current = DateUtil.current();
|
||||
|
@ -1,20 +0,0 @@
|
||||
package cn.hutool.core.date;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TimeIntervalTest {
|
||||
@Test
|
||||
public void intervalGroupTest(){
|
||||
final TimeInterval timer = new TimeInterval();
|
||||
timer.start("1");
|
||||
ThreadUtil.sleep(800);
|
||||
timer.start("2");
|
||||
ThreadUtil.sleep(900);
|
||||
|
||||
|
||||
Console.log("Timer 1 took {} ms", timer.intervalMs("1"));
|
||||
Console.log("Timer 2 took {} ms", timer.intervalMs("2"));
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package cn.hutool.core.reflect;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.date.TimeInterval;
|
||||
import cn.hutool.core.date.StopWatch;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.lang.test.bean.ExamInfoDict;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
@ -88,18 +87,20 @@ public class MethodUtilTest {
|
||||
// 预热
|
||||
getMethodWithReturnTypeCheck(ReflectUtilTest.TestBenchClass.class, false, "getH");
|
||||
|
||||
final TimeInterval timer = DateUtil.timer();
|
||||
final StopWatch timer = new StopWatch();
|
||||
timer.start();
|
||||
for (int i = 0; i < 100000000; i++) {
|
||||
MethodUtil.getMethod(ReflectUtilTest.TestBenchClass.class, false, "getH");
|
||||
}
|
||||
Console.log(timer.interval());
|
||||
timer.stop();
|
||||
Console.log(timer.getLastTaskTimeMillis());
|
||||
|
||||
timer.restart();
|
||||
timer.start();
|
||||
for (int i = 0; i < 100000000; i++) {
|
||||
getMethodWithReturnTypeCheck(ReflectUtilTest.TestBenchClass.class, false, "getH");
|
||||
}
|
||||
Console.log(timer.interval());
|
||||
timer.stop();
|
||||
Console.log(timer.getLastTaskTimeMillis());
|
||||
}
|
||||
|
||||
public static Method getMethodWithReturnTypeCheck(final Class<?> clazz, final boolean ignoreCase, final String methodName, final Class<?>... paramTypes) throws SecurityException {
|
||||
|
@ -2,11 +2,11 @@ package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.collection.ConcurrentHashSet;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.date.TimeInterval;
|
||||
import cn.hutool.core.date.StopWatch;
|
||||
import cn.hutool.core.exceptions.UtilException;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.lang.id.Snowflake;
|
||||
import cn.hutool.core.lang.id.IdUtil;
|
||||
import cn.hutool.core.lang.id.Snowflake;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
@ -48,18 +48,21 @@ public class IdUtilTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void benchTest() {
|
||||
final TimeInterval timer = DateUtil.timer();
|
||||
final StopWatch timer = DateUtil.createStopWatch();
|
||||
timer.start();
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
IdUtil.simpleUUID();
|
||||
}
|
||||
Console.log(timer.interval());
|
||||
timer.stop();
|
||||
Console.log(timer.getLastTaskTimeMillis());
|
||||
|
||||
timer.restart();
|
||||
timer.start();
|
||||
for (int i = 0; i < 1000000; i++) {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
UUID.randomUUID().toString().replace("-", "");
|
||||
}
|
||||
Console.log(timer.interval());
|
||||
timer.stop();
|
||||
Console.log(timer.getLastTaskTimeMillis());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1,6 +1,6 @@
|
||||
package cn.hutool.extra.aop.aspects;
|
||||
|
||||
import cn.hutool.core.date.TimeInterval;
|
||||
import cn.hutool.core.date.StopWatch;
|
||||
import cn.hutool.core.lang.Console;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
@ -13,7 +13,7 @@ import java.lang.reflect.Method;
|
||||
public class TimeIntervalAspect extends SimpleAspect {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final TimeInterval interval = new TimeInterval();
|
||||
private final StopWatch interval = new StopWatch();
|
||||
|
||||
@Override
|
||||
public boolean before(final Object target, final Method method, final Object[] args) {
|
||||
@ -23,10 +23,11 @@ public class TimeIntervalAspect extends SimpleAspect {
|
||||
|
||||
@Override
|
||||
public boolean after(final Object target, final Method method, final Object[] args, final Object returnVal) {
|
||||
interval.stop();
|
||||
Console.log("Method [{}.{}] execute spend [{}]ms return value [{}]",
|
||||
target.getClass().getName(), //
|
||||
method.getName(), //
|
||||
interval.intervalMs(), //
|
||||
interval.getLastTaskTimeMillis(), //
|
||||
returnVal);
|
||||
return true;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.date.TimeInterval;
|
||||
import cn.hutool.core.date.StopWatch;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.net.SSLProtocols;
|
||||
import cn.hutool.core.net.url.UrlBuilder;
|
||||
@ -68,24 +68,31 @@ public class HttpRequestTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void asyncGetTest() {
|
||||
final TimeInterval timer = DateUtil.timer();
|
||||
final StopWatch timer = DateUtil.createStopWatch();
|
||||
timer.start();
|
||||
final HttpResponse body = HttpRequest.get(url).charset("GBK").executeAsync();
|
||||
final long interval = timer.interval();
|
||||
timer.restart();
|
||||
timer.stop();
|
||||
final long interval = timer.getLastTaskTimeMillis();
|
||||
timer.start();
|
||||
Console.log(body.body());
|
||||
final long interval2 = timer.interval();
|
||||
timer.stop();
|
||||
final long interval2 = timer.getLastTaskTimeMillis();
|
||||
Console.log("Async response spend {}ms, body spend {}ms", interval, interval2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void syncGetTest() {
|
||||
final TimeInterval timer = DateUtil.timer();
|
||||
final StopWatch timer = DateUtil.createStopWatch();
|
||||
timer.start();
|
||||
final HttpResponse body = HttpRequest.get(url).charset("GBK").execute();
|
||||
final long interval = timer.interval();
|
||||
timer.restart();
|
||||
timer.stop();
|
||||
final long interval = timer.getLastTaskTimeMillis();
|
||||
|
||||
timer.start();
|
||||
Console.log(body.body());
|
||||
final long interval2 = timer.interval();
|
||||
timer.stop();
|
||||
final long interval2 = timer.getLastTaskTimeMillis();
|
||||
Console.log("Async response spend {}ms, body spend {}ms", interval, interval2);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user