【发布时间】:2012-10-28 06:59:44
【问题描述】:
我正在开发一个基于散列的程序。 我的问题是字符串的 HashCode 是否会在整个应用程序中保持不变。
我问这个的原因是,Mecached Servers 中的 KetamaMemcachedSessionLocator 以这种方式工作 如果有两台服务器正在运行 Memcache,我想从特定服务器中找到一个密钥。
String key = "MyString";
int keyid = key.hashCode();
int v = keyid % 1; //( I assume that this will contact the First Server to retrieve that value )
int v = keyid % 2; //( I assume that this will contact the Second Server to retrieve that value )
String value = MemcachedClient.get(key, v);
以下基于本网站实现上述内容
http://dev.mysql.com/doc/refman/5.0/en/ha-memcached-using-hashtypes.html
请分享您的意见,如果您发现任何问题,如果上述方式有效。
【问题讨论】:
标签: java