Add synchronized keyword for getSize() method