Received: from SOUTH-STATION-ANNEX.MIT.EDU by po10.MIT.EDU (5.61/4.7) id AA16571; Tue, 25 Apr 00 16:59:56 EDT Received: from hermes.javasoft.com by MIT.EDU with SMTP id AA03659; Tue, 25 Apr 00 16:58:52 EDT Received: (from nobody@localhost) by hermes.java.sun.com (8.9.3+Sun/8.9.1) id VAA14345; Tue, 25 Apr 2000 21:00:06 GMT Date: Tue, 25 Apr 2000 21:00:06 GMT Message-Id: <200004252100.VAA14345@hermes.java.sun.com> X-Authentication-Warning: hermes.java.sun.com: Processed from queue /bulkmail/data/ed_2/mqueue6 X-Mailing: 198 From: JDCTechTips@sun.com Subject: JDC Tech Tips April 25, 2000 To: JDCMember@sun.com Reply-To: JDCTechTips@sun.com Errors-To: bounced_mail@hermes.java.sun.com Precedence: junk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Beyond Email 2.2 J D C T E C H T I P S TIPS, TECHNIQUES, AND SAMPLE CODE WELCOME to the Java Developer Connection(sm) (JDC) Tech Tips, April 25, 2000. This issue covers: * Improving Serialization Performance with Externalizable * Handling Those Pesky InterruptedExceptions This tip was developed using Java(tm) 2 SDK, Standard Edition, v 1.2.2. You can view this issue of the Tech Tips on the Web at http://developer.java.sun.com/developer/TechTips/2000/tt0425.html. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IMPROVING SERIALIZATION PERFORMANCE WITH EXTERNALIZABLE The February 29, 2000 Tech Tip on serialization (http://developer.java.sun.com/developer/TechTips/2000/tt0229.html), explored the flexibility of Java's serialization mechanism. With serialization, you can customize how an object's fields are mapped to a stream, and even recover when you encounter a stream that has different fields from the ones you expect. This flexibility is a benefit of the serialization format; the format includes more then just your object's field values, but also metadata about the version of your class and its field names and types. However, flexibility comes at the price of lower performance. This is certainly true for serialization. This tip shows you how to improve the performance of serialization by turning off the standard serialization format. You do this by making your objects externalizable. Let's start the tip with a programming example that uses serializable objects: import java.io.*; class Employee implements Serializable { String lastName; String firstName; String ssn; int salary; int level; public Employee(String lastName, String firstName, String ssn, int salary, int level) { this.lastName = lastName; this.firstName = firstName; this.ssn = ssn; this.salary = salary; this.level = level; } } public class TestSerialization { public static final int tests=5; public static final int count=5000; public static void appMain(String[] args) throws Exception { Employee[] emps = new Employee[count]; for (int n=0; n