使用hadoop序列化机制时的一点小问题
其实在现在接触到的数据处理中还没怎么碰到到需要自己实现序列化对象的情况。偶然看到一篇文章,说的是由于偷懒而造成序列化和反序列化时造成的不必要的时间和空间消耗。其实如果自己遇到这种问题,应该也会使用同样偷懒的方法。这里说明一下,以便提醒自己要这么做时,是否考虑到了性能方面的问题。
原文地址:http://teddziuba.com/2008/04/dont-serialize-java-object-in.html
@Overridepublic void write(DataOutput out) throws IOException {ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();ObjectOutputStream objectOut = new ObjectOutputStream(byteOutStream);objectOut.writeObject(getContainedObject());objectOut.close();byte[] serializedObject= byteOutStream.toByteArray();out.writeInt(serializedObject.length);out.write(serializedModel);}