• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

K&B Ch. 9: two Questions

 
blacksmith
Posts: 979
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I've got two questions regarding some statements
in K&B's chapter 'Threads'.
First Question: on pg. 508 it says:

But Objective 7.2 is looking for your ability to
recognize when a thread will get kicked out of running
but not sent back to either runnable or dead.


The while covering the same objective 7.2 on pg 513

What yield() is supposed to do is make
the currently running thread head back to runnable to
allow other threads of the same priority to get their
turn.


At first glance it seems to me that what it says on
pg 508 shouldn't exclude methods (i.e. yield) that
send the thread back to the runnable state. But
am I missing some important detail?
Second Question: on pg. 510 it says:

When a thread encounters a sleep call, it must
go to sleep for at least the specified number of
milliseconds (unless it is interrupted before its
wake-up time, in which case it immediately throws the
InterruptedException).


Shouldn't at least be at most? Since the time
after the duration in milliseconds is really spent
in the runnable state and not sleeping?
Thanks,
Gian Franco
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As for the first question, I'm going to have a difficult time answering that out of context (I don't have that book). For that one, I'll simply defer to someone else.
For the second question, I agree that the sleep time in a "minimum" time. When you provide a duration for a thread to sleep, it will sleep for at least that long. When that time period is up, that thread would move to the runnable state, but you don't know when it might move to the running state. If some other thread is hogging the processor, the original thread's sleep time might expire and then have to wait even longer before it can run.
Corey
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

But Objective 7.2 is looking for your ability to
recognize when a thread will get kicked out of running
but not sent back to either runnable or dead.


I don't think this is a final statement. It's one of the things you need to know to cover Objective 7.2. It's saying you need to know there are more states other than runnable or dead. You need to know that to be able to "Recognize conditions that might prevent a thread from executing" (Objective 7.2). But it doesn't mean that's all you need to know. As you point out, you also need to understand yield to cover the objective.
That's the way I read it anyway ...
reply
    Bookmark Topic Watch Topic
  • New Topic