• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SurfaceHolder.Callback surfaceDestroyed()

 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ed,

I noticed that the behavior of the example in the book was different from the Lunar Lander example.

In the book, in Chapter 10 (p 187) -



In Lunar Lander example, the call is made inside a loop catching the InterruptedException -


Looks like the first version might cause a problem if the thread is interrupted.
Will that be a problem in practice?

Cheers,
Sonny
 
Ed Burnette
Author
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I asked a friend who knows more about Java joins and interrupts than I do and he said you're right. The second code snippet is more correct because if the current thread is interrupted while blocked in the join(), the first code will not actually join; it will continue on before the thread it has waiting for has finished. It needs to be in a loop as well. The flag retry gets reset if the join() returns successfully.

I've never encountered this in practice but it doesn't hurt to code defensively.

(It doesn't hurt to have smart friends down the hall either)
 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Ed. Good to know for sure.
Ed Burnette wrote:
(It doesn't hurt to have smart friends down the hall either)


Absolutely! And I am guessing that they are thinking the same thing
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic