<< Ubuntu 9.10: First Impressions | Home | Hmmm... >>

Friday Java Quiz: Can Your Thread Withstand My Interruption

It has been 1267 days since Java Concurrency in Practice was published. I trust that all self-respecting Java programmers have read the book cover-to-cover. Today's Friday Quiz is a concurrency one.

Q: Will the following Java class compile? Run without exceptions? If so, what does it print?

import java.util.concurrent.BlockingQueue; 
import java.util.concurrent.LinkedBlockingQueue; 
 
public class Foo { 
    public static void main(String[] args) throws InterruptedException { 
        BlockingQueue<Integer> q = new LinkedBlockingQueue<Integer>(); 
        q.put(1); 
        Thread.currentThread().interrupt(); 
        System.out.println(q.take()); 
    } 
}

Strict rules apply: No actual compiling, peeking into the book, or surfing the web for Javadocs or other clues is allowed for the first 30 minutes.

Bonus Q: How many authors are named on the cover of Java Concurrency in Practice? Name three of them.

Bonus QQ: Name the other three.



Re: Friday Java Quiz: Can Your Thread Withstand My Interruption

No idea on the main question, but for the bonus Q, I'm going to go with '6' (unless the 'bonus QQ' is a trick question), and I know three of them are Brian Goetz, Doug Lea, and Josh Bloch. Can't remember the others though. Tim someone? What do I win? I hope it's made out of chocolate, whatever it is, I'm starving.

Re: Friday Java Quiz: Can Your Thread Withstand My Interruption

q is an unbounded blocking queue so put shouldn't block, interrupt would raise an exception if the thread is in blocked state e.g waiting on I/O or on a Lock ... since it is not the case, the println should proceed and print 1.
I believe the main authors are Brian Goetz and David Holmes. The other names, big maybes: Doug Lea, Tim Petriels ( probably butchering the name) Joshua Block and Martin Buscholtz
Cheers,
Khalil

Add a comment Send a TrackBack