Lock the batch before calling java, to avoid registering batch more than once