This jar is being called by a multi-threaded application (ITIM). So how would I go about reserving zzxxx1 until the first user is finished being created so as to not have duplicate usernames.
If this is a cluster configuration (i.e. distributed applications running on multiple servers) then you are going to have to have some sort of central service that guarantees the uniqueness of the names. One easy solution would be a database with unique constraints on the username field in some table. Each server could do something like an ordered LIKE
query to find the highest username number and then try to create an entry using the next number. If it was taken it would try again with the next number...
Another solution would be to have a central service which does the uniqueness guarantee. All of the cluster nodes would contact the central one which would use a synchronized
or other lock to ensure that only one thread is generating a unique name at a time. Then again I assume you need persistence so maybe the database is the easiest option.