public class PersistentAnimation implements Serializable, Runnable
{
private Thread animator;
private int animationSpeed;
public PersistentAnimation(int animationSpeed)
{
this.animationSpeed = animationSpeed;
animator = new Thread(this);
}
public void run()
{
while(true)
{
// do animation here
}
Here animator is not marked as transient? Will it still be persisted?
No, because Thread does not implement the
Serializableinterface. You’ll have an exception when trying to serialize an instance of this class.Straight from the javadoc of Serializable: