java - 调试自定义多线程缓存
问题描述
我有一个包含 32 个缓存对象的数组,每 20 秒后我会定期刷新每个缓存。下面附上代码片段。
我观察到很少有缓存在一些刷新周期后停止刷新,并且日志中没有打印异常。请注意,应用程序没有崩溃,但某些缓存没有被刷新。
public class CacheManager
{
private static class CacheRefresher extends Thread
{
Cache cache;
public CacheRefresher(Cache cache)
{
this(cache);
}
@Override
public final void run()
{
try {
LOG.info("cache is getting refreshed for " + cache.type);
cache.refreshCache();
}
catch (Exception e) {
String subject = "Cache refresh failed in BMW";
LOG.log(Level.WARN, subject + ". Exception thrown:", e);
}
}
}
public void refreshCaches(List<cache> caches)
{
ThreadFactory ourThreadFactory =
new NamedThreadFactory("CacheHandler", true);
ScheduledExecutorService scheduleService =
Executors.newScheduledThreadPool(32, ourThreadFactory);
initialDelay = 60;
for (Cache cache : caches) {
service.scheduleWithFixedDelay(new CacheRefresher(cache), initialDelay, 20, TimeUnit.SECONDS);
initialDelay += 2;
cacheContainers.add(cache);
}
}
}
是否有可能一个线程超过了最大堆限制并且抛出了错误,但是由于我没有发现错误,所以我没有观察到它?
但我不确定如果一个线程抛出内存不足错误,那么整个应用程序会停止还是只有一个线程会受到影响?任何意见?
解决方案
推荐阅读
- css - Vue JS 媒体查询不起作用,即使它在正确的层次结构中,它也不会覆盖基本 css
- javascript - 如何关闭 Heroku 服务器进行维护?
- reactjs - 尝试导入错误:“unstable_useId”未从“@material-ui/core/utils”导出(导入为“useId”)
- presto - case when 语句不支持如何解决给定的相关子查询
- python - 为什么python不断抛出'源代码字符串不能包含空字节'
- python-3.x - 如何在 Python scipy 的伽马概率密度函数中获得特定 x 值的概率?
- django - 如何自定义 django-rosetta admn 页面
- c# - 是否存在等待而不返回的多个 Task.Run 的开销?
- azure - Azure Durable Functions:我可以使用 startup.cs 吗?
- amazon-web-services - 为什么我会大量收到来自投诉@email-abuse.amazonses.com 的电子邮件?