java - IllegalArgumentException - 当主机仅包含 0B 物理内存时尝试分配 256MB 内存
问题描述
上下文:将 java 升级到 java 1.8.0_281 后,应用程序无法启动。在 java 代码中,我试图为堆外缓存分配一些内存,定义如下:
<cache-template name="myCache">
<expiry>
<none/>
</expiry>
<resources>
<heap unit="entries">100000</heap>
<offheap unit="MB">256</offheap>
<disk unit="MB">1000</disk>
</resources>
</cache-template>
但我在启动时收到以下错误:
Caused by: java.lang.IllegalStateException: Cache 'myCache' creation in EhcacheManager failed.
at org.ehcache.core.EhcacheManager.createCache(EhcacheManager.java:302)
at org.ehcache.core.EhcacheManager.createCache(EhcacheManager.java:252)
at org.ehcache.jsr107.Eh107CacheManager.createCache(Eh107CacheManager.java:201)
(......这里有更多堆栈跟踪......如果需要,我会提供它)
Caused by: org.ehcache.StateTransitionException: Attempting to allocate 256MB of memory when the host only contains 0B of physical memory
at org.ehcache.core.StatusTransitioner$Transition.succeeded(StatusTransitioner.java:209)
at org.ehcache.core.EhcacheBase.init(EhcacheBase.java:569)
at org.ehcache.core.EhcacheManager.createCache(EhcacheManager.java:275)
at org.ehcache.core.EhcacheManager.createCache(EhcacheManager.java:252)
at org.ehcache.jsr107.Eh107CacheManager.createCache(Eh107CacheManager.java:201) ~[ehcache-3.9.0.jar:3.9.0 97b6a73ef8644dc028234f166c90f951f60f099b]
(……)
看到 0B 物理内存很奇怪,因为根据我的检查,运行应用程序的 linux 服务器有足够的内存。我读到,在大多数情况下,交换的内存连接到堆外内存。所以我解决这个问题的第一个想法是增加交换内存,因为一开始它是0。但是这样做并重新启动服务器后,错误仍然存在。
使用的命令:free
结果:
total used free shared buffers cached
Mem: 30221268 27787476 2433792 546780 344464 22443644
-/+ buffers/cache: 4999368 25221900
Swap: 1023996 0 1023996
另一个提到,在另一个使用相同 java 版本的 linux 服务器上,应用程序运行良好并且启动良好。
我错过了什么吗?为什么我会收到这个错误?我还能检查什么?
欢迎任何帮助。
解决方案
推荐阅读
- node.js - 反应脚本:找不到命令(npm start)
- c# - BinaryFormatter 字节使用情况
- arrays - 使用聚合的MongoDB变换数组
- ios - 对于内容完全在应用程序之外开发但在应用程序上预览的 CE 平台,是否需要应用程序内购买?
- ios - 在应用程序中支持戴口罩时使用 Apple Watch 解锁 FaceID
- visual-studio - Visual Studio 2019 键盘停止响应或不断重复字符
- python - 连接熊猫中列的值
- c++ - 如何将 DirectX 动画捕获为视频
- vba - WORD VBA 搜索并切换到高级
- python - 使用 partial() 进行多处理会引发 ForkingPickler 错误