【问题标题】:Is there any way to free JVM memory in @AfterChunks in spring batch?有没有办法在春季批处理中释放 @AfterChunks 中的 JVM 内存?
【发布时间】:2020-03-09 15:41:13
【问题描述】:

有没有办法释放@AfterChunks 中的JVM 内存?因为我们在处理了几条记录后遇到了 outOfMemory 错误。

春季批处理作业完成后有没有办法释放内存?

    Public class ABC implements ChunkListener{

    private static final Logger log = oggerFactory.getLogger(ABC .class);
    private MessageFormat fmt = new MessageFormat("{0} items processed");

    private int loggingInterval = 100;

    @Override
    public void beforeChunk(ChunkContext context) {
        // Nothing to do here
    }

    @Override
    public void afterChunk(ChunkContext context) {

        int count = context.getStepContext().getStepExecution().getReadCount();

        // If the number of records processed so far is a multiple of the logging interval then output a log message.           
        if (count > 0 && count % loggingInterval == 0) {
            log.info( fmt.format(new Object[] {new Integer(count) })) ;
        }
        //String name = context.getStepContext().getStepName();
        //context.getStepContext().registerDestructionCallback(name, callback);

    }

如何拨打registerDestructionCallback清理?什么是名称和回调?有参考吗?

【问题讨论】:

    标签: spring-boot out-of-memory spring-batch


    【解决方案1】:

    在 Java 中无法强制进行 GC(System.gc() 只是对 JVM 的提示),您应该将其留给 GC。

    面向块的步骤中的项目应在处理每个块后进行垃圾收集,请参阅Does Spring Batch release the heap memory after processing each batch?。如果您有 OOM,请确保:

    • 您的项目不属于处理器、映射器等
    • 一个块可以放入内存:有时,使用driving query pattern,处理器会获取有关每个项目的更多详细信息,并且您可以很快地为前几个项目耗尽内存

    【讨论】:

    • 你好,我和作者有同样的问题,还是不明白为什么。似乎我的物品被某物持有(我没有看到其他任何东西)但是在哪里:/如果您可以查看我的帖子:stackoverflow.com/questions/63487684/… 谢谢
    猜你喜欢
    • 1970-01-01
    • 2019-08-25
    • 2021-12-28
    • 1970-01-01
    • 2020-02-12
    • 1970-01-01
    • 2014-12-15
    • 2018-05-27
    • 2015-05-13
    相关资源
    最近更新 更多