added missing synchronized blocks for avoiding concurrency issues

Same as previous comment