Article View: aus.computers.java
Article #27Concurrent modification
From: mario
Date: Sun, 15 Aug 2004 10:50
Date: Sun, 15 Aug 2004 10:50
70 lines
3400 bytes
3400 bytes
Hi guys,
I'm trying to solve a problem it's giving me an headhache. I'm a
newbie in java lang. I'm developing a web spider using jericho
libraries. My classes take a url, connect to it, put all the unique
links present in the html page in a Hashtable as key, then it takes
all the words of the page and put it as value of each key. What I need
is a recursive system that cycle through the hashtable and put new
found links in the Hashtable so the cycle would notice it and continue
until all the links have been parsed.
This is an example of what I would need
public class Parse {
public static Hashtable linksList = new Hashtable();
public static String url = "http://myaddress.com"
public static doParse() {
linksList.put(url,new Hashtable());
//generic cycle to fill the hashtable
for (Enumeration en = linksList.keys(); en.hasMoreElements(); )
{
String urlToParse = en.nextElement();
parse(htmlText);
}
}
public static parse(String url) {
String htmlText = Connection.getString(url); //get the html of
a given url
Hashtable words = getWords(htmlText); //get all the words of a
given html text
linksList.put(url, words);
for (... all the links in a fiven htmlText) {
String newUrl; //each new links found in the given html
text
linksList.put(newUrl, new Hashtable());
}
}
}
As you can see the parse method add recursively new hashtable element
for each new url it found.
The generic cycle should be aware of the change that has been made and
go on until the parse method
won't add any new link. This would let me to fill the hashtable with
an url and the words contained in that
url for all the pages in a particoular site. Then, when my ht would be
completely filled I would add
it to a db, having only one connection to it.
How would I do that? I see that HT doesn't see any changes made to
itself inside a cycle. What other
object I should use? Any other idea on how to perform it? I looked
through the internet but I only found
solution on how to avoid the concurrentModificationException on
ArrayList, not code samples on how to
do it.
I really hope you can help me as I'm stuck with this problem and have
no idea on how to solve it
Thanks a lot in advance!!!
Bye for now!
mario
Technical Details
Message-ID:
<8qfuh0treqoarja44hh958p293g1ajjg85@4ax.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!news-fra1.dfn.de!news-lei1.dfn.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!nntp.infostrada.it!twister2.libero.it.POSTED!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10d6db,e6864c5a77839819,start X-Google-Attributes: gid10d6db,public X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!news-fra1.dfn.de!news-lei1.dfn.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!nntp.infostrada.it!twister2.libero.it.POSTED!not-for-mail From: mario <marioSPAMNO@emmedici.com> Newsgroups: aus.computers.java Subject: Concurrent modification Reply-To: marioSPAMNO@emmedici.com Message-ID: <8qfuh0treqoarja44hh958p293g1ajjg85@4ax.com> X-Newsreader: Forte Agent 1.93/32.576 Italiano MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 70 Date: Sun, 15 Aug 2004 10:50:52 GMT NNTP-Posting-Host: 151.25.222.143 X-Complaints-To: abuse@libero.it X-Trace: twister2.libero.it 1092567052 151.25.222.143 (Sun, 15 Aug 2004 12:50:52 MET DST) NNTP-Posting-Date: Sun, 15 Aug 2004 12:50:52 MET DST Organization: [Infostrada]