Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RingBufferWheel 有内存溢出隐患 #98

Closed
daoshenzzg opened this issue Jul 1, 2020 · 1 comment · Fixed by #99
Closed

RingBufferWheel 有内存溢出隐患 #98

daoshenzzg opened this issue Jul 1, 2020 · 1 comment · Fixed by #99
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@daoshenzzg
Copy link

Bug 描述
RingBufferWheel 的 task 保存在 taskMap(HashMap) 中,而 remove(key)、cancel(id) 并没有对 taskMap 中进行 remove 操作。

复现
复现步骤:

private static class ByteTask extends RingBufferWheel.Task {

        private byte[] b;

        public ByteTask(int size) {
            this.b = new byte[size];
        }

        @Override
        public void run() {
        }
    }
    private static void test1() throws InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        RingBufferWheel wheel = new RingBufferWheel(executorService);
        while (true) {
            logger.info("task size={}, task map size={}", wheel.taskSize(), wheel.taskMapSize());
            TimeUnit.SECONDS.sleep(1);

            for (int i = 0; i < 1000; i++) {
                RingBufferWheel.Task task = new ByteTask(1024 * 1024);
                task.setKey(1);
                wheel.addTask(task);
            }
        }
    }

预期结果

截图

12:38:26.557 [main] INFO RingBufferWheelTest - task size=0, task map size=0
12:38:27.575 [main] INFO RingBufferWheel - delay task is starting
12:38:30.872 [main] INFO RingBufferWheelTest - task size=323, task map size=1000
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at RingBufferWheelTest$ByteTask.<init>(RingBufferWheelTest.java:64)
	at RingBufferWheelTest.test1(RingBufferWheelTest.java:26)
	at RingBufferWheelTest.main(RingBufferWheelTest.java:14)

附加信息

@crossoverJie crossoverJie added bug Something isn't working good first issue Good for newcomers labels Jul 1, 2020
crossoverJie added a commit that referenced this issue Jul 4, 2020
@crossoverJie crossoverJie mentioned this issue Jul 4, 2020
@crossoverJie
Copy link
Owner

已经修复,参考:

private static void test8() throws Exception{
ExecutorService executorService = Executors.newFixedThreadPool(2);
RingBufferWheel wheel = new RingBufferWheel(executorService);
while (true) {
logger.info("task size={}, task map size={}", wheel.taskSize(), wheel.taskMapSize());
TimeUnit.SECONDS.sleep(1);
for (int i = 0; i < 1000; i++) {
RingBufferWheel.Task task = new ByteTask(1024 * 1024);
task.setKey(1);
wheel.addTask(task);
}
}
}

huskyui pushed a commit to huskyui/cim that referenced this issue Sep 7, 2020
Zwanningmoon pushed a commit to Zwanningmoon/cim that referenced this issue Dec 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants