java - Multi-Threaded application, making new threads on the fly? -


right have program gui indexes url specify. need index 15 things @ time , have been opening 15 windows of program , individually inputting urls want index. these 15 url's change every hour or so... have separate program stores these 15 changing urls in table in mysql database. able fetch these urls database(i store them in arraylist) im not sure how go multi-threading application dont have manual work of inputing urls application.

my question: can give me example/link me tutorial of how go creating new thread each url in arraylist(also arraylist change need make new thread changing arraylist aswell?)

ive looked @ java site on concurrency , high level concurrency didn't understand examples gave(i still beginning programmer please bear me)

hopefully explained im trying enough detail in advance

edit: urls index change every couple of seconds why dont think can go through method each url 1 after another, hence why believe needs multithreaded?

2nd edit(i believe these guys understand im asking):

@jon storm there 2 issues going on 1) getting url list 2) accessing said urls. make url fetcher single-threaded , dispatch out thread pool of fetchers. dispatcher can queue pending fetches, etc. – pst

@jon storm: please update question describe want more explicitely? if in understood correctly, want index list of 15 urls again , again, because contents of pages @ these urls changes every 3 seconds. , want update list of urls index every hour, getting them database. right? – jb nizet

it seems me problem not multi-threading, inputting in gui application fetching urls database.

why don't reuse class (or of code, if it's impossible reuse classes is) of gui application (i.e. url indexing method) inside application fetches urls database.

my guess index these 15 urls 1 after other, in single thread. try doing before trying use threads.

the program this:

  1. fetch 15 urls database , put them list
  2. iterate through list , index each url
  3. sleep time,
  4. go 1

edit:

since seems urls must indexed again , again until list of urls changes, use algorithm:

  1. create thread pool using executors.newcachedthreadpool()
  2. get urls database
  3. for each url, create task index url again , again, until interrupted (check thread.interrupted() returns false @ each iteration)
  4. submit each task executorservice created @ step 1, , keep returned future inside list
  5. sleep/wait until list of urls index changes
  6. cancel each future (cancel(true)) of list of future instances
  7. go step 2.

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -