Archive for November, 2008

Make your own chandelier

Saturday, November 22nd, 2008

When my housemate and I moved into our new place we weren’t thrilled with the victorian-style knockoff chandelier that was in our living room. Our friend recommended we paint it and see if we still wanted to throw it out. So, I took the idea and ran with it. Needless to say, it’s definitely not getting thrown out any time soon. Here is a picture of the finished product.



This was a pretty simple project and started out with a beat up old chandelier. I took it down and cleaned it off as best I could with soap and water. Then I sprayed it with some white primer before hitting it with two coats of high gloss orange. That was the easy part and didnt take too long.


Next I had to track down some small lamp shade covers. I came across a nice set of 8 at lampsplus.com. First thing I did when I got them was template. This was crucial in cutting out 5 copies from the fabric. I simply wrapped a big enough piece of paper around the lamp shade and taped it. Then I trimmed up all the excess and unwrapped it. Voila template.



(click the image to see it larger)


After all of the fabric was cut out it was time to warm up the glue gun. Make sure to try and line up the fabric seam with the seam thats already on the lamp shade. First I glued one side down where I wanted it, then I would take out all the slack and wrinkles and fold the over the other side. Dont worry about making this perfect. Once you fold over the top and button around the lamp shade rim you can deal with the rest of the slack.



(click the image to see it larger)


And thats it! There’s not much to it and it didnt take long. I was able to save an old chandelier from the dump and go something completely original in return. There are more pictures up on Flickr including one of the completed room.

Can you see the concurrency flaw?

Monday, November 3rd, 2008

A coworker and I came across this block of code which was causing us numerous headaches over the past few weeks. For a while, there was absolutely no time delay which was causing an inordinate amount of CPU cycles but thats besides the point. After that was fixed with a short delay we were left with what you see below. Can you tell what’s wrong?


   while ( true ) {
        TriggeredSend ts = queue.peek();
        if ( ts != null ) {
            switch( doPost( ts ) ) {
                case SUCCESS:
                    queue.take();
                    ts.complete( true );
                    break;
                case FAILURE:
                    queue.take();
                    ts.complete( false );
                    break;
                case SYSTEM_UNAVAILABLE:
                    systemIsAvailable = false;
                    break;
            }
        }
        Thread.sleep( delay );
   }


As with most concurrency bugs, its hard to determine what’s actually happening without experience. You can turn on your debugger but then you are changing the way the code behaves by slowing it down, essentially taking out any race conditions. Turns out, the same task was getting invoked multiple times well as some other strange conditions. That led us to the block of code you see above.


Figure it out yet? Well, what’s happening is that when the code is peeking into the queue, its assigning the result to a variable which is then being called. According to the java.util.concurrency spec, the peek method is used to see if the queue has tasks in it and not used to take any tasks off the queue. Not only that, but after the task was invoked, another task was being pulled off the queue. So what happens when multiple threads come through that block of code and peek? Well, they can both get the same task and invoke it. Bad bad bad.