aspose file tools*
The moose likes Java in General and the fly likes Concurrency question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Concurrency question" Watch "Concurrency question" New topic
Author

Concurrency question

Vadim Vararu
Ranch Hand

Joined: Jan 03, 2009
Posts: 147


A) Compilation fails.
B) An exception is thrown at runtime.
C) "BeginRunEnd" is printed.
D) "BeginEndRun" is printed.
E) "BeginEnd" is printed.

The correct answer is C, but i don't know why. I think it can be "BeginRunEnd", but also "RunBeginEnd" in case thread "a" succeds to print "Run" before the "main" thread prints "Begin". Do you have idea why the only correct answer (according to the site) is C?


If you think you've done too much, usually it means you've done too few.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3054
    
  33

Please QuoteYourSources


Mohamed Sanaulla | My Blog
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

You are right, the result is either RunBeginEnd or BeginRunEnd. All you can say is that End is printed last.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36467
    
  15
On a multiple-choice exam, one must find one "correct" answer and four "incorrect" answers. "C" is correct, but the other four are incorrect. It is a bit like the following question about swimming-pools:

What might happen if you dive into a swimming-pool full of cold water?
  • A: You remain dry
  • B: You suffer flame burns
  • C: Your swimming costume comes off
  • D: You hit your head on an ocean liner
  • E: You are eaten by an Ichthyosaurus
  • The answer is obviously C, because you cannot stay dry or suffer flames burns in a swimming-pool, and ocean liners or Ichthyosauri are never found in swimming-pools. There are all sorts of other possible right answers, eg
  • You get wet
  • All the girls think you are manly and attractive
  • All the men think you are feminine and attractive
  • You win a prize for diving
  • You swim away
  • . . . but those are not given as possibilities. So "your swimming custome comes off" is the only possible correct answer available for that question.

    Yes, I have known it happen, once, when I was at school.
    Rob Spoor
    Sheriff

    Joined: Oct 27, 2005
    Posts: 19541
        
      16

    Campbell Ritchie wrote:All the girls think you are manly and attractive

    I think you mean "all the girls are repulsed by your large tummy"
    Mohamed Sanaulla
    Saloon Keeper

    Joined: Sep 08, 2007
    Posts: 3054
        
      33

    Interesting analogies coming from Campbell these days Or is it the usual?

    But agree- with MCQs we need not worry about the answers which are not given as options. But always better to read the question carefully as you may end up selecting the right answer, but you were asked to select the wrong answers
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 36467
        
      15
    Rob Prime wrote:. . . "all the girls are repulsed by your large tummy" . . .
    How did you know that?
    Rob Spoor
    Sheriff

    Joined: Oct 27, 2005
    Posts: 19541
        
      16

    who says I was talking about you
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: Concurrency question
     
    Similar Threads
    Thread question from www.scjptest.com
    Threads Question
    Help in a question about Threads