I found the solution for this. Just wrap the code in a single thread.
But I have another question about CLI. I add a security-domain successfully by CLI in Java code using ModelControllerClient. The new domain also showed in jconsole but in LoginContext, it does not exist and I cannot use it for authentication.
Any one know how to flush the new added security-domain in Java code? Thanks a lot!