这段实例化的代码可以优化提速吗?# Java - 爪哇娇娃
b*i
1 楼
某个类的文件本地读入和处理需要0.5秒,我就想能不能串行化,然后我直接读入。结
果发现,直接本地读入object需要1秒。下面就是代码,请问有没有办法加速?obj文件
一共几百k bytes.
public static Object load(String filename){
try {
FileInputStream fin = new FileInputStream(filename);
ObjectInputStream ois = new ObjectInputStream(fin);
Object obj = ois.readObject();
ois.close();
System.out.println("unserialized theQueue");
return obj;
} catch (Exception e) { e.printStackTrace(); }
return null;
}
果发现,直接本地读入object需要1秒。下面就是代码,请问有没有办法加速?obj文件
一共几百k bytes.
public static Object load(String filename){
try {
FileInputStream fin = new FileInputStream(filename);
ObjectInputStream ois = new ObjectInputStream(fin);
Object obj = ois.readObject();
ois.close();
System.out.println("unserialized theQueue");
return obj;
} catch (Exception e) { e.printStackTrace(); }
return null;
}