This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Errata to errata of SCJP study guide by K. Sierra & BB

 
John Brown
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The errata says that:


Page 505,Second paragraph

Change:
.. method has finished, you can't say t.start(); you'll get a big fat runtime exception.

To:
.. method has finished, calling t.start() won't restart it.


But we know that the 1.4.2 API states that start() throws IllegalThreadStateException - if the thread was already started.
So the errata is wrong, isn't it?
See also this topic Thread Q from Sierra & Bates SCJP Study Guide.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if you get a runtime exception, t.start() won't restart the thread. It seems like both statements are correct to me.

Layne
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I remember correctly, for Java 1.4, calling start() on a thread which had finished its run() method did not cause the exception to be thrown. The exception was only thrown if the thread could be still executing run() while start() was called a second time. That's why the statement was changed in the errata.

In Java 5.0 it appears that the exception is now thrown when calling start() on such a "dead" thread.
[ January 23, 2006: Message edited by: Barry Gaunt ]
 
John Brown
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the answers.

Layne, if the phrase "you'll get a big fat runtime exception" is true, why was it eliminated via the errata? I thought the errata was supposed to correct things which weren't right ?

Barry, you remember correctly, for Java 1.4, calling start() on a thread which had finished its run() method does not cause the exception to be thrown, the exception is only thrown if the thread is still executing run() while start() is called a second time.

But according to the API, this behaviour is wrong:

public void start()[...] Throws: IllegalThreadStateException - if the thread was already started.


Now, if the thread is dead, that means it was already started, isn't it? So if the thread is dead (it's run() method has finished), then calling start() on this dead thread should throw an IllegalThreadStateException, right?
 
John Brown
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Page 536:
If start() is called more than once on a Thread object, it will throw a RuntimeException.


This is in agreement with the API. But the errata is not.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Unfortunately the reality is that some (maybe all?) Sun JDKs prior to JDK 5 did not obey the spec in this regard. Which makes this a poor test question unfortunately, though it's not the author's fault so much as tbe fault of some unknown Sun programmers(s). Anyway, the way I read the errata, "calling t.start() won't restart it" is a true statement, which is intentionally ambiguous about exactly how & why the thread won't restart. Maybe start() will throw an exception (as per the spec), or maybe start() will just return immediately with no effect (as per the buggy reality in JDK 1.4).

Errata are often written under the constraint that the replacement text cannot change the page numbering of the other text. Because the author and publisher are typically trying to just make small modifications that can go into the next printing of the book, without having to re-index the rest of the book. In this case, it would've taken somewhat more space to fully discuss the fact that the spec and implementation give contradictory results. And so I'm guessing K&B thought it was more appropriate to give a short vague-but-true answer to replace the previous answer which is specific-but-false under existing JDKs.
[ February 01, 2006: Message edited by: Jim Yingst ]
 
Bert Bates
author
Sheriff
Posts: 8900
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jim's my hero!
 
Joshua Smith
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think there needs to be an errata for the link to the errata in the first post of this thread. :-) The link is to errata for things that were detected and fixed in 2003!

Anyone have the link to the new errata? I actually have a couple of items that I've found in my copy of the book and want to see if anyone else has discovered them.

Thanks,
Josh
 
Bert Bates
author
Sheriff
Posts: 8900
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Joshua -

We'll be posting a link to the Java 5 errata page in a few days,
 
John Brown
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jim, thanks for your answer.
Yes I agree (always had) that the phrase "calling t.start() won't restart it" is a true statement, I was just confused about the reason the errata was striking the phrase "you'll get a big fat runtime exception", and the errata does that only for the 505 page, and not for the 536 and 508 pages.

So, if I get a question on this topic on the exam, what's the answer? is an exception thrown or not? I would be inclined to answer that with a yes.
[ February 02, 2006: Message edited by: John Bran ]
 
Joshua Smith
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bert.

Josh
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic