Take a look at this one. By the way, feel free to write two different threads and see how observer can help with this. This code looks much like mandarin to me.