confused with source code

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

confused with source code

lzcn0775
I'm confused with source code in class AbstractSerialStateHolder.I cannt understand the stream = new ThreadLocal<ObjectOutputStream>(),in the function writeExternal,when os=null,new a ObjectOutputStream,but in the end stream.remove().so why use a ThreadLocal stream?can some body expain?The source code as below:
@Override 
  public final void writeExternal(final ObjectOutput out) throws IOException { 
    boolean firstRound = false
    final ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    ObjectOutputStream os = stream.get(); 
    if (os == null) { 
      os = new ObjectOutputStream(baos); 
      firstRound = true
      stream.set(os); 
    } 
 
    os.writeObject(this.userBean); 
    os.writeObject(this.unloadedProperties); 
    os.writeObject(this.objectFactory); 
    os.writeObject(this.constructorArgTypes); 
    os.writeObject(this.constructorArgs); 
 
    final byte[] bytes = baos.toByteArray(); 
    out.writeObject(bytes); 
 
    if (firstRound) { 
      stream.remove(); 
    } 
  }

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.