Since it was not thread safe, add 'synchronized'.

Since it was not thread safe, add 'synchronized'.