Site hosted by Angelfire.com: Build your free website today!
 

Transient Fields

Some objects may contain fields that you don't want to persist, for example a Thread and OutputStream and its subclasses. For these fields, you should mark it as transient:

import java.io.Serializable;
public class PersistentAnimation implements Serializable, Runnable {
 transient private Thread animator;
 private int animationSpeed;
 public PersistentAnimation(int animationSpeed) {
   this.animationSpeed = animationSpeed;
   animator = new Thread(this);
   animator.start();
 }
 public void run() {
   while(true) {
       // do animation here
   }
 }
}