通过核心API调用System.gc() [英] System.gc() calls by core APIs

查看:175
本文介绍了通过核心API调用System.gc()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你们中的一些人可能知道一些核心java API对System.gc()进行了明确的调用。我知道发生这种情况的两种情况:


  1. NIO。当系统用完直接内存时,我相信这样做是为了对直接ByteBuffers进行一些清理。

  2. RMI。在这里,原因对我来说不是那么清楚......

所以,问题是:


  1. 是否知道RMI需要System.gc()的原因?

  2. 当核心API(或甚至一些其他流行的库)可以直接调用System.gc()?


解决方案

如果有分布式对象需要清理,RMI会调用System.gc()。您可以减少执行GC的次数或将其关闭。

您可以避免直接ByteBuffer需要GC在Sun / Oracle JVM上通过调用

  ByteBuffer bb = ByteBuffer.allocateDirect(SIZE); 
((DirectBuffer)bb).cleaner()。clean();


Some of you probably know that some of core java APIs make explicit calls to System.gc(). I know two cases when this happens:

  1. NIO. I believe that is done to do some cleanup for direct ByteBuffers, when system runs out of "direct" memory.
  2. RMI. Here, the reason is not that clear for me...

So, questions are:

  1. Do know reason why System.gc() is required for RMI?
  2. Do you know any other situations when core APIs (or even some other popular libraries) can make a direct call to System.gc()?

解决方案

RMI calls the System.gc() in case there are distributed objects which need to be cleaned up. You can make it perform GC less often or effectively turn it off.

You can avoid direct ByteBuffer needing a GC to clean them up on the Sun/Oracle JVM by calling

ByteBuffer bb = ByteBuffer.allocateDirect(SIZE);
((DirectBuffer) bb).cleaner().clean();

这篇关于通过核心API调用System.gc()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆