mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package cn.hutool.core.collection;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MemorySafeLinkedBlockingQueueTest {
|
||||
|
||||
@Test
|
||||
public void offerTest(){
|
||||
final MemorySafeLinkedBlockingQueue<String> queue = new MemorySafeLinkedBlockingQueue<>(Integer.MAX_VALUE);
|
||||
Assert.assertFalse(queue.offer("123"));
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
package cn.hutool.core.thread;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.util.RuntimeUtil;
|
||||
|
||||
/**
|
||||
* 简单定时任务测试
|
||||
*/
|
||||
public class SimpleSchedulerTest {
|
||||
public static void main(final String[] args) {
|
||||
|
||||
// 新建一个定时任务,定时获取内存信息
|
||||
final SimpleScheduler<Long> scheduler = new SimpleScheduler<>(new SimpleScheduler.Job<Long>() {
|
||||
private volatile long maxAvailable;
|
||||
|
||||
@Override
|
||||
public Long getResult() {
|
||||
return this.maxAvailable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
this.maxAvailable = RuntimeUtil.getFreeMemory();
|
||||
}
|
||||
}, 50);
|
||||
|
||||
// 另一个线程不停获取内存结果计算值
|
||||
ThreadUtil.execAsync(() -> {
|
||||
//noinspection InfiniteLoopStatement
|
||||
while (true) {
|
||||
Console.log(FileUtil.readableFileSize(scheduler.getResult()));
|
||||
ThreadUtil.sleep(1000);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user