Commit 35ebe843 authored by yanzg's avatar yanzg

将源码打包进jar包

parent f11c0a43
...@@ -66,10 +66,11 @@ public class Timeout<T> { ...@@ -66,10 +66,11 @@ public class Timeout<T> {
return false; return false;
} }
long prevTime = now - prev; long prevTime = now - prev;
try { // System.out.println(String.format("now %d time %d prev %d prevTime %d ", now, time, prev, prevTime))
return prevMaxTime > prevTime; boolean ret = prevTime > prevMaxTime;
} finally { if (ret) {
this.prev = now; this.prev = now;
} }
return ret;
} }
} }
import com.yanzuoguang.cloud.aop.Timeout;
import com.yanzuoguang.util.thread.ThreadHelper;
import org.junit.Test;
public class TestTimeout {
@Test
public void testTimeout() {
Timeout<Integer> timeout = new Timeout<>(1);
long maxTime = 1000;
long start = System.currentTimeMillis();
long prev = start;
while (maxTime > 0) {
long now = System.currentTimeMillis();
long runTime = now - start;
long waitTime = now - prev;
prev = now;
maxTime -= waitTime;
if (timeout.isMaxTime(10, 20)) {
System.out.println("执行时间" + runTime);
}
ThreadHelper.sleep(10);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment