Reputation: 47805
use case example
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
Upvotes: 0
Views: 224
Reputation: 68268
The PermGen
overflow is not an issue. However:
String.intern()
is a heavyweight operation, since it requires locking the String constant pool. This will reduce your throughput;More importantly, you will synchronise on objects which 'escape' your control, e.g. if a library you use has a
synchronized ("a") {
// do stuff
}
block somewhere, you will deadlock without knowing it. It's more or less the same issue as synchronising on Boolean
or Integer
values. I suggest you use your own locks for this.
Upvotes: 1
Reputation: 147154
To your question: Perm gen should be able to code with 65,536 one character String
s (should only be a few megs).
However:
String
s).Upvotes: 1