Results 1 to 4 of 4
- 11-18-2008, 08:39 AM #1
Member
- Join Date
- Mar 2008
- Posts
- 43
- Rep Power
- 0
ConcurrentModificationException with ArrayList
Hello,
I am building a binarytree ADT for storing a dictionary. My underlying data structure is an arraylist, which is a global in my binarytree class.
My algorithm to build the tree works something like this:
The problem is that I always get the ConcurrentModificationException ( I tried to post the URL here ).Java Code:Take an ArrayList take the middle element and set it as the root of the tree split the tree at that middle element and set the left and right pointer of the root to the left and right subtrees. recursively call this method, adding the middle elements to the global ArrayList
My question is, how can I modify a node's (constructed in my "node" class) pointers without getting this problem?
(I could swear this whole project would have taken me 1 hour tops in python. I just spend all my time with these errors.)
Thanks!
- 11-18-2008, 01:01 PM #2
If another thread makes structural modifications to a Collection, in general we get a concurrent modification exception. There has to be a barrier that will ....
uh, it sorta gets complicated but the short version is that we would make a complete new Tree and set the pointers to the new Tree. Which operation would have to block all access to the tree during update. Individual record locking does not lend to the Collections design.
That devolves into some convoluted design consequences, a robust / time-critical design can be achieved with (synchronized) code construct - but that is going to be difficult to do with large collections as a complete array copy operation has to intervene between T(n) and T(n+1) access of either read or write as reads can be done but will throw on a write the structurally modifies the tree structure.Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 11-18-2008, 08:33 PM #3
Member
- Join Date
- Mar 2008
- Posts
- 43
- Rep Power
- 0
I seriously cannot build a new tree for every iteration. We are talking about a 600kb, 80,000 line dictionary here.
How would you write bubble sort in java if the list you were sorting was global?
- 01-15-2009, 04:04 AM #4
I would use a TreeMap, I have code for a WordCount, which I will share with you if you want. I could stand to look at it now - my skills are greater than when I wrote it and it is a super-critical part of my original project. That has not gotten any attention in very long time..
Shortened version is just do TreeMap dot add( new Integer( String.hashcode(), new String( the original string ) )
btw thanks to EFH at JR for me getting that running.
I only tested it once, if you will do some testing - I will share it with you.Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Similar Threads
-
Java Project Trouble: Searching one ArrayList with another ArrayList
By BC2210 in forum New To JavaReplies: 2Last Post: 04-21-2008, 11:43 AM -
ArrayList
By ramitmehra123 in forum New To JavaReplies: 1Last Post: 02-07-2008, 12:47 AM -
ArrayList
By kizilbas1 in forum New To JavaReplies: 1Last Post: 01-12-2008, 08:48 PM -
New to arraylist
By kleave in forum New To JavaReplies: 2Last Post: 11-19-2007, 06:45 PM -
Help ArrayList.add()
By eNine in forum New To JavaReplies: 2Last Post: 08-06-2007, 01:13 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks