NullPointerException
Chris Lamprecht
clamprecht at gmail.com
Mon Oct 15 16:32:17 UTC 2007
Hi Dustin,
I'm calling MemcachedClient from inside a webapp under Tomcat 5.5, and it is
definitely being hit from multiple clients (multiple threads) at the same
time. I don't have assertions enabled. Here's how I'm calling
MemcachedClient:
constructing:
memcache = new MemcachedClient(new InetSocketAddress(host, port));
Get from cache:
private Map<String, Object> getStuff(Collection<Integer> ids) {
StringBuilder buf = new StringBuilder(500);
for (int id : ids) {
buf.append("cacheditem:").append(id).append(' ');
}
String request = buf.toString().trim();
Map<String, Object> map = memcache.getBulk(request);
log.debug("Requested "+ids.size()+" items from cache, got "+map.size()+"
items back");
return map;
}
Put items in the cache:
public void putInCache(Collection<MyItem> itemsToCache, Map<Integer, Long>
itemLastmodifiedDates) {
for (MyItem j : itemsToCache) {
int id = j.getId();
String cachedItemKey = "cacheditem:" + jobId;
memcache.set(cachedItemKey, 0, j);
Long lastModifiedDate = itemLastmodifiedDates.get (id);
if (lastModifiedDate == null)
throw new IllegalArgumentException("itemLastmodifiedDate not
found in map for id "+id);
memcache.set("itemlastmodified:" + id, 0, lastModifiedDate);
}
}
Delete items from cache (when items are updated in the DB):
private void delete(int id) {
log.debug("Deleting id "+id);
String key = Integer.toString(id);
memcache.delete ("cacheditem:" + key);
memcache.delete("itemlastmodified:" + key);
}
That's the bulk of it.. there's a bit more to deal with items that have been
updated in the database, and it then removes those items from the cache,
which is why I'm storing the lastmodified date for each item.
Let me know if you want me to try anything, add logging statements, etc.
Thanks,
Chris
On 10/15/07, Dustin Sallings < dustin at spy.net> wrote:
>
>
> On Oct 14, 2007, at 19:06, Chris Lamprecht wrote:
>
> public void gotData(String key, int flags, byte[] data) {
> Collection<GetOperation.Callback> cbs=callbacks.get(key);
> assert cbs != null : "No callbacks for key " + key;
> for(GetOperation.Callback c : cbs) { <---- NPE here
> c.gotData(key, flags, data);
> }
> }
>
> Any ideas? I haven't dug into the code yet to try and debug it. Also
> previously I tried the 1.4 client version and got an NPE in
> OptimizeGet.java or something like that. Thanks
>
>
> Are you running with assertions enabled?
>
> Can you describe what kinds of operations you have running through this?
> I've never seen that assertion fire nor had an NPE there, so I'd be curious
> how much you could tell me about what may have led to this state.
>
> --
> Dustin Sallings
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.danga.com/pipermail/memcached/attachments/20071015/7674447b/attachment-0001.html
More information about the memcached
mailing list