Maddy
Maddy

Reputation: 389

JLS: Item 54 - Why classes having thread pool should not implement serializable?

From what I understand, the object state is just stored (values for fields, etc.), however, the execution context is anyways going to be lost.

What's the point of this? What bad can happen if so?

Note* this was taken from Effective Java By Joshua Bloch

Upvotes: 0

Views: 103

Answers (1)

Stephen C
Stephen C

Reputation: 718826

The execution context of a Thread consists of

  • the Java stack,
  • the snapshot of the hardware registers taken when the thread is suspended, and
  • other state such as the thread's presence in scheduler queues, and so on.

Since none of this information can be saved by serialization, the serialized Thread is useless.

Upvotes: 1

Related Questions