why people bother to interview here (Part 1)

I have just gotten out of yet another interview with a “senior” Java candidate who doesn’t know threading at all. Please don’t claim you are a senior candidate unless you can answer this basic question.


public class Foo {
    public static final Foo INSTANCE_1 = new Foo();
    public static final Foo INSTANCE_2 = new Foo();

    public static synchronized method1() { /* really long execution */ }
    public        synchronized method2() { /* really long execution */ }
    public static              method3() { /* really long execution */ }
    public                     method4() { /* really long execution */ }
    public static synchronized method5() { /* really long execution */ }
    public        synchronized method6() { /* really long execution */ }
}

Now pretend that there are these threads running on a 64000-core machine. Each thread, at the exact same picosecond, makes a call to the method listed:

Thread Method call
Thread 101

    Foo.INSTANCE_1.method1();
Thread 102

    Foo.INSTANCE_1.method2();
Thread 103

    Foo.INSTANCE_1.method3();
Thread 104

    Foo.INSTANCE_1.method4();
Thread 105

    Foo.INSTANCE_1.method5();
Thread 106

    Foo.INSTANCE_1.method6();
Thread 111

    Foo.INSTANCE_1.method1();
Thread 112

    Foo.INSTANCE_1.method2();
Thread 113

    Foo.INSTANCE_1.method3();
Thread 114

    Foo.INSTANCE_1.method4();
Thread 115

    Foo.INSTANCE_1.method5();
Thread 116

    Foo.INSTANCE_1.method6();
Thread 201

    Foo.INSTANCE_2.method1();
Thread 202

    Foo.INSTANCE_2.method2();
Thread 203

    Foo.INSTANCE_2.method3();
Thread 204

    Foo.INSTANCE_2.method4();
Thread 205

    Foo.INSTANCE_2.method5();
Thread 206

    Foo.INSTANCE_2.method6();
Thread 211

    Foo.INSTANCE_2.method1();
Thread 212

    Foo.INSTANCE_2.method2();
Thread 213

    Foo.INSTANCE_2.method3();
Thread 214

    Foo.INSTANCE_2.method4();
Thread 215

    Foo.INSTANCE_2.method5();
Thread 216

    Foo.INSTANCE_2.method6();
Thread 301

    new Foo(){ }.method1();
Thread 302

    new Foo(){ }.method2();
Thread 303

    new Foo(){ }.method3();
Thread 304

    new Foo(){ }.method4();
Thread 305

    new Foo(){ }.method5();
Thread 306

    new Foo(){ }.method6();

Questions:

  1. Now which threads will block each other and why?
  2. Where are locks stored? (The JVM has to store the information some place!)
  3. What is a deadlock?
  4. When do deadlocks occur? Does the above code experience a deadlock?

No, the answer is not going to be given.

This post is labeled Part 1 because there will be more rants in this area I am sure!

Update: 12 April 2011: more detailed!

This entry was posted in interviewing, starting a company, technical. Bookmark the permalink.

One Response to why people bother to interview here (Part 1)

  1. Pingback: why people bother to interview here – if you can’t teach (Part 2) « Just wondering….

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>