用java读1000万行记录到Arraylist里面?Java 中 static 和 volatile 关键字的区别

时间:2018-01-07 14:20:02   浏览:次   点击:次   作者:   来源:   立即下载

附 设置了heap size,用了命令 java -Xms②⑤⑥m -Xmx ①⓪②④m classname。

还是heapsize 不够溢出。 机器是⑧g的内存

-Xmx 为何不能设置过大,

HashMapString, ArrayListString map=new HashMapString, ArrayListString();

try {

BufferedReader fReader=new BufferedReader(new FileReader("D:/ww.csv"));

String str=null;

while((str=fReader.readLine())!=null)

{

String[]strings=str.split(

代码贴出来, @黄亿华大哥已经回答得很好了,可以先试①试确定。arralylist在扩容的时候有复制数组的操作

public boolean add(E e) {ensureCapacity(size + ①); // Increments modCount!!elementData[size++] = e;return true; }public void ensureCapacity(int minCapacity) {modCount++;int oldCapacity = elementData.length;if (minCapacity > oldCapacity) { Object oldData[] = elementData; int newCapacity = (oldCapacity * ③)/② + ①; if (newCapacity < minCapacity)newCapacity = minCapacity; // minCapacity is usually close to size, so this is a win: elementData = Arrays.copyOf(elementData, newCapacity);} }最后调用的是下面这个①个native方法

System.arraycopy(Object src, int srcPos, Object dest, int destPos,int length)这么大的东西复制过去你想想好吗?

可以用链表而不是array!

ps:(为什么看到

System.gc();)我感觉不是太舒服,不知道你要干嘛

而且你代码的问题貌似不出在这个问题上啊!亲\", \"extras\": \"\", \"created_time\": ①④②⑧⑦⑦①①②⑦ · \"type\": \"answer

The explanation from @David is OK.

Try to simplify his answers for the volatile.

In Java, a thread can have its own local memory.

Declaration of a volatile variable means that the value referred by this variable will never be cached thread local memory, and all operations(read/write) will go to the value in the main memory directly.

收起

相关推荐

相关应用

平均评分 0人
  • 5星
  • 4星
  • 3星
  • 2星
  • 1星
用户评分:
发表评论

评论

  • 暂无评论信息