Fix concurrency problem in PubSub

Added Synchronized on methods. Not the best way to do it but it's
working.