我刚刚在我们的生产环境中遇到了相当不愉快的经历 OutOfMemoryErrors: heapspace..
我将这个问题追溯到我ArrayList::new
在函数中的使用.
要通过声明的构造函数(t -> new ArrayList<>()
)验证这实际上比正常创建更糟糕,我编写了以下小方法:
public class TestMain {
public static void main(String[] args) {
boolean newMethod = false;
Map<Integer,List<Integer>> map = new HashMap<>();
int index = 0;
while(true){
if (newMethod) {
map.computeIfAbsent(index, ArrayList::new).add(index);
} else {
map.computeIfAbsent(index, i->new ArrayList<>()).add(index);
}
if (index++ % 100 == 0) {
System.out.println("Reached index "+index);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
运行方法newMethod=true;
将导致方法OutOfMemoryError
在索引达到30k后失败.随着newMethod=false;
程序不会失败,但一直冲击直到被杀(索引容易达到150万).
为什么在堆上ArrayList::new
创建如此多的Object[]
元素会导致OutOfMemoryError
如此之快?
(顺便说一下 - 当集合类型出现时也会发生HashSet …
我有一个问题,显示存储为多个日期的多个日期.我使用带有long参数的构造函数创建日期对象,然后将日期打印到PDF文件.
但是,与Windows相比,在Linux上运行程序时,我遇到了较旧的日期问题.
以此日期为例:1976年4月25日00:00:00(长值:199231200000L).如果我使用dateformater来显示日期,它将在Linux和Windows上以不同方式显示:
在Windows上:1976年4月25日00:00:00 CEST
在Linux上:1976年4月24日23:00:00 CET
文字代表.只需运行以下行即可显示:
DateFormat.getDateTimeInstance( DateFormat.FULL, DateFormat.FULL ).format( new Date( 199231200000L) )
Run Code Online (Sandbox Code Playgroud)
我使用Joda Time来获取此测试的日期值:
new org.joda.time.DateTime().withDate( 1976, 4, 25 ).withTime( 0, 0, 0, 0 ).toDate().getTime()
Run Code Online (Sandbox Code Playgroud)
为什么Windows将输出显示为CEST,Linux显示为CET?
我在我们的网站上遇到了 Chromeautocomplete
似乎无法正常工作的问题。它过去一直有效,但并非始终如一。
例如,我有一个input
这样的字段:
<input type="text" class="gwt-TextBox Inputfield TextInputfield form-control" maxlength="40" name="name" autocomplete="name" width="0" style="max-width: 26em; width: 100%;">
Run Code Online (Sandbox Code Playgroud)
当我开始输入我的名字时,autocomplete
下拉菜单会按预期打开,但是当我在autocomplete
下拉菜单中选择我的名字时,除了下拉菜单关闭之外什么也没有发生。
控制台中没有记录异常。
带有字段的页面在这里。