See Java serialization performance - a simple example

xiaoxiao2021-03-06  63

My article EJB told me how to fall in love with you - "Proficient in EJB" and EJB, mentioning the performance of Java serialization is very low, at least Sun provides the performance of JDK, which gives a simple test program Proof I: First construct a simple test class class class1 imports serializable {int m_nint = 1; long m_nlong = 2; double m_double = 3; string m_sstring = "test"; int getint () {return m_nint;} void setInet (int nInt) {m_nInt = nInt;} long getLong () {return m_nLong;} void setLong (long nLong) {m_nLong = nLong;} double getDouble () {return m_dDouble;} void setDouble (double dDouble) {m_dDouble = dDouble } String getString () {return m_sstring;} void setstring (String SString) {m_sstring = sstring;} public string toxmlstring () {return " getint () " " "" getlong () "" "" getDouble () " " " getString () " " "";}} This class, I also wrote a toxmlstring method. You can see that this is a very simple way to pack the data into an XML string and then write a serialization method test, compare the Java sequence Method and I wrote to TO yourself long lStartTime = System.currentTimeMillis ();; for (int i = 0; i <100000; i ) {ByteArrayOutputStream baos = new ByteArrayOutputStream () method of the performance of public XMLString testSerilize () throws Exception {Class1 obj = new Class1 () void ObjectOutputStream OOS = New ObjectOutputStream (baos); OOS.WriteObject (obj); byte [] data = baos.tobyteaRray ();} system.out.println ("Serialize Used Time:"

转载请注明原文地址:https://www.9cbs.com/read-119874.html

New Post(0)