我生成了一个hashmap,生成文件到硬盘中存贮,显示大小为2.2G
tomcat启动时需要把该hashmap读入内存中。
tomcat的java虚拟机开到了9G,可是读此文件时,竟然内存溢出了,谁知道什么原因,谢谢了。
写文件和读文件的代码见下:hashmap 是 类似这样的结构:key:中国 value:是ArrayList, list(0)=中国人,list(1)=中国人民,list(2)=中国人大。。 // 写入文件
public static void write(Object o, String filename) {
try {
//File file=new File(filename);
// if(!file.exists()){
//file.createNewFile();
//}
ObjectOutputStream w = new ObjectOutputStream(new FileOutputStream(
filename));
w.writeObject(o);
w.flush();
w.close();
} catch (Exception e) {
e.printStackTrace();
}
} // 读取文件
public static Object Reader(String file) {
try {
ObjectInputStream in = new ObjectInputStream(new FileInputStream(
file));
Object o = in.readObject();
in.close();
return o;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
tomcat启动时需要把该hashmap读入内存中。
tomcat的java虚拟机开到了9G,可是读此文件时,竟然内存溢出了,谁知道什么原因,谢谢了。
写文件和读文件的代码见下:hashmap 是 类似这样的结构:key:中国 value:是ArrayList, list(0)=中国人,list(1)=中国人民,list(2)=中国人大。。 // 写入文件
public static void write(Object o, String filename) {
try {
//File file=new File(filename);
// if(!file.exists()){
//file.createNewFile();
//}
ObjectOutputStream w = new ObjectOutputStream(new FileOutputStream(
filename));
w.writeObject(o);
w.flush();
w.close();
} catch (Exception e) {
e.printStackTrace();
}
} // 读取文件
public static Object Reader(String file) {
try {
ObjectInputStream in = new ObjectInputStream(new FileInputStream(
file));
Object o = in.readObject();
in.close();
return o;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
解决方案 »
- 谁有java web整合开发王者归来
- 本人菜鸟,请教个问题:用SSH编程,如何查看完整的sql语句。还有我查出来的对象列表里边的对象从哪里取到?
- java程序基础问题?
- 2*8问题
- hibernate在myeclipse中怎么生成啊?
- tomcat启动后 ,启动applet发生异常,帮忙啊哈急
- 用JBuilder 2005如何编写Web Service客户端程序???
- hibernate双向一对多查不到多的一方
- 在web.xml里servlet-mapping映射了两个路径,tomcat5.0.28下找不到项目路径,请问是兼容性的问题吗?!!!!
- 我的第一个struts程序就出现奇怪错误???
- 求教hibernate动态建表!
- 一个javascript的单引号困扰。。。。
这么大的数据全部加载到内存中,期待高手给个答案-先MARK下;