Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Reproducing a sync issue with linked list  RSS feed

 
Mike Finger
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I'm having what I believe is a synchronization issue at a client site (we're trying to reproduce it in house) under heavy load.
We're using win2k/jdk1.4.1_02/jrun 4 server with sp2. What is happening is the server is not responding, but no java thread dump (we've scoured the hd several times to be sure).
Anyways, when I scour the server logs i'm finding tons of:
09/29 10:06:52 error
java.util.NoSuchElementException
at java.util.LinkedList.remove(LinkedList.java:575)
at java.util.LinkedList.remove(LinkedList.java:347)
at com.sctechnology.util.cache.ArrayCache.add(ArrayCache.java:95)
at com.sctechnology.util.cache.CacheManager.setItem(CacheManager.java:342)
at com.sctechnology.delegate.actor.User.addToCache(User.java:332)
at com.sctechnology.delegate.actor.User.addToCache(User.java:321)
at com.sctechnology.delegate.actor.User.getInstance(User.java:285)
at com.sctechnology.action.UtilitiesAction.getUser(UtilitiesAction.java:154)
at com.sctechnology.action.view.ShowViewAction.perform(ShowViewAction.java:68)
at org.apache.struts.action.ActionServlet.processActionPerform(ActionServlet.java:1787)
at com.svtechnology.util.ActionServlet.processActionPerform(ActionServlet.java:146)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1586)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:492)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at jrun.servlet.FilterChain.doFilter(FilterChain.java:86)
at jrun.servlet.security.StandardSecurityFilter.doFilter(StandardSecurityFilter.java:103)
at jrun.servlet.FilterChain.doFilter(FilterChain.java:94)
at jrun.servlet.security.JSecurityCheckFilter.doFilter(JSecurityCheckFilter.java:70)
at jrun.servlet.FilterChain.doFilter(FilterChain.java:94)
at jrun.servlet.FilterChain.service(FilterChain.java:101)

The cache object basically uses a linkedlist to impliment LRU cache. The methods that access the linkedlist object are syncronized, but
I'm not convinced they're 100% thread safe (i.e. the get method removes the item someone is getting and moves it to the back, it's one syn. method, while the add method adds an object and checks to make sure the maxsize hasn't been reached, if so it removes some elements, etc).
So the question: Can is get java.util.NoSuchElementException from a linkedlist due to it not being thread safe?
And perhaps more importantly - how would I reproduce it? I made a thread test harness to hammer on the cache object, but no luck...\
Even a simple proof of concept using linked list in a multi threaded enviroment would sufice. I've been able to un syncronize ind. methods have interesting meltdowns, but I haven't been able to force the cache into a nosuchelement exception.
I'm reluctant to ship a fix off the client without knowing what's wrong (The hardest part!!!), because I'm not 100% convinced
it's unsafe threading and not bad code logic.
Thanks
Mike
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.util.NoSuchElementException
at java.util.LinkedList.remove(LinkedList.java:575)
at java.util.LinkedList.remove(LinkedList.java:347)
at com.sctechnology.util.cache.ArrayCache.add(ArrayCache.java:95)
at com.sctechnology.util.cache.CacheManager.setItem(CacheManager.java:342)
at com.sctechnology.delegate.actor.User.addToCache(User.java:332)
at com.sctechnology.delegate.actor.User.addToCache(User.java:321)

I looked at the source of LinkedList.java, and matching it with your stack trace gives us the following: your ArrayCache.add() method tries to evict an element from the LinkedList by calling the method remove(int index), which in turn calls a private method remove(Entry e), which in turn throws a NoSuchElementException. Here is 1.4.1 implementation of LinkedList:

So, it looks like your code tries to remove an element from an empty list. Notice, however, that in a single thread it would be impossible to reproduce using the remove(int index) method, because any attempt to invoke the remove(int index) on an empty list would result in the IndexOutOfBoundsException, rather than NoSuchElementException. Therefore, the problem does appear to be with threads.
If you still cannot reproduce the problem with a simple multithreaded test using this information, let us know and we figure it out.
It would also help if you post your code for the ArrayCache and CacheManager classes.
[ October 01, 2003: Message edited by: Eugene Kononov ]
 
Mike Finger
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eugene,
Thanks for the info. Our client is also using a quad proc box with hyper-threading , which I suspect might increase the chances for a threading conflict on non-thread safe code?
Thanks
Mike
[ October 01, 2003: Message edited by: Mike Finger ]
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Our client is also using a quad proc box with hyper-threading , which I suspect might increase the chances for a threading conflict on non-thread safe code?
As I mentioned, if you post your code for the ArrayCache and CacheManager classes, it would be much easier for us to identify the problem.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!