Replaced java synchronization by a native one.