Sunday
Mar152009

Muchas Motos!!!

­We opened the riding season with the Duel Sport Ride organized by San Francisco Motorcycle Club. It seemed it would rain any moment, but the weather held nice.

I came to the club on time, when I realized my tank was dry. I went to the closest gas station, got my gas, and tried to catch up with the group that already took off. I kept catching up until I realized that there is no way a bunch of hairy Harley riders will drive so far ahead. I then started suspecting that I was ahead of the group and asked a group of Mexican day workers if they saw a bunch of bikes. The did not understand. Then I spread my hands wide and said "many many bikes". Then one of them told the others "Muchas motos!!!" and I knew they got my question. They all nodded "no", so I knew that the group was behind me. I made a U-turn, they all waving at me, and rode back about half a mile until I heard the humming sound of a bunch of bikes approaching me from around the corner. Excited that I found my group, I made another U-turn and continued riding with them. We all passed by the same group of Mexicans and they all were jumping and waving at me, they seemed happy that I found my group.

The ride was smooth, the club members were guarding every red light, and every stop sign, allowing the bikes to drive without having to stop.

Friday
Mar062009

They Won

My friends keep asking when will I finally create a Flickr profile for my photos. They got what they want. Ladies and gentlemen, here is my photostream. As a teaser, here is a picture of Erin in the flight and Dave's awesome front cover shot.

Monday
Mar022009

True Beauty


It was the season finale of one of the most ridiculous shows I've ever seen -- True Beauty. 10 high maintenance looking people competed to be the most beautiful person in America. The winner ended up being one of the former Miss Teen USA contestants, a sweet girl from Texas.

Here are the finalists of my very own True Beauty contest. The winner is... (dramatic pause) (commercial)... (and we are back)... and the winner is (dramatic pause) FLUFFY!!!! The runner up is a henna painting from our neighborhood south Indian restaurant Dosa, the third place got a dead leaf, and the fourth got my drawing.

Friday
Feb272009

Photo Friday by the Swamp

Another week, another Photo Friday. This time, the star was Sparky. We went for a walk alongside a gnarly swamp, smelling whiffs of stench every few seconds. But hey, you can not smell it when you see the pictures! On the upper left picture from the left: Dustin, Sparky (the star), Joey, and Dave. Bottom photos from the left: Ed with his eastern-German Pentacon, Peter with his Canon, and Brad. Thanks to Dustin for letting me borrow the 50 mm lens. Message for Sparky: Wait till Fluffy appears in all her starliciousness and takes the spotlight!!!

Thursday
Feb262009

Java Concurrency In Practice (Part 1)

I highly recommend this book about Java concurrency. I extracted some of the main points from the book and will draft them out in this and the following blog posts.

When do you need synchronization:

  • when multiple threads access the same mutable state variable
3 ways to do it:
  • don't share the state variable across threads (isolation)
  • make the state variable immutable (immutability)
  • use synchronization whenever accessing the state variable (locking)
No state => no thread safety issues because stateless objects are always thread safe

COMPOUND ACTIONS NEED ATOMICITY:
BAD:
 private long count = 0;
 public long getCount() { return count; }
  public void doSomething() {
  blah blah
  ++count;
// this contains 3 operations: read, increment, write
                    // they can be interrupted by other threads that see data in a bad state
}

GOOD:
  private final AtomicLong count = new AtomicLong();
  public long getCount() { return count.get(); }

  public void doSomething() {

    blah blah

    count.incrementAndGet();
  }

  • If there are more variables that form an invariant, you need to update related state variables in a single atomic operation.
  • if possible, try to use existing thread-safe objects, like AtomicLong to manage your class's state

RACE CONDITIONS
  • Commonly found in check-then-act where a potentially stale observation is used to make a decision on what to do next.
  • example of check-then-act: LAZY INITIALIZATION
        BAD:
          private ExpensiveObject instance = null;
          public ExpensiveObject getInstance() {
            if (instance == null) // this line can be executed by two threads at the same time and two ExpensiveObjects will get

                                                                                  // newed. That will make getInstance() return two different intances
               instance = new ExpensiveObject();

            return instance;

          }