add write lock to make the js invoke thread safe.