use case example
- I have a servlet that is receiving login requests.
- If a login is currently in process OR the user is already logged in, the servlet should abort and inform the caller.
current design
Taking inspiration from database sharding, I plan to use the first character of each userid as a synchronization key.
void login( String userid )
{
  String first = userid.substring(0, 1);
  synchronized( first.intern() )
  {
    // query the cache or database for a session token.
    // if session token exists, throw an exception
  }
}
questions
- I understand that using String#intern might overflow the permgen space. In my case, the string being dumped into permgen is a single Unicode character. Am I safe in using interned strings this way ?
 
     
     
    