This commit is contained in:
Looly
2022-06-18 14:04:20 +08:00
parent 4ebec434a1
commit 103738d9ef
6 changed files with 259 additions and 7 deletions

View File

@@ -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"));
}
}

View File

@@ -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);
}
});
}
}