Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #10373

Re: Thread question

From Daniel Pitts <newsgroup.nospam@virtualinfinity.net>
Newsgroups comp.lang.java.programmer
Subject Re: Thread question
References <i9tbd7ppgalucct4i2t2agj9hldjumnmk4@4ax.com>
Message-ID <ZLvBq.1201$X02.458@newsfe03.iad> (permalink)
Date 2011-11-30 11:48 -0800

Show all headers | View raw


On 11/30/11 1:31 AM, Roedy Green wrote:
> The application is I have a list of 1200 books and a list of 21 online
> bookstores.  I want to find out which bookstores carry the book.  I
> have code now that given a book and bookstore will find out if it
> carries it and records the result.  It probes the appropriate page and
> scans for clues, positive and negative.
>
> The process is very slow because it mostly spends its time waiting for
> the bookstore to respond.  I figured I could fairly easily make one
> book-x-store probe into a Runnable. Happily there is only very simple
> interactions between Runnables.
>
> You could imagine setting all the Runnables loose at once.
>
> I need two features:
>
> 1. some sort of throttle on releasing them that I don't swamp the JVM.
> 2. some  way of knowing when the last one completed.
>
> I could do this by having my Runnables increment and decrement global
> counts, however I suspect there is something built in to handle this
> flawlessly.
>
> There are so many tools. I wonder if anyone would like to point me to
> the most appropriate one for this task.
>
> If I get this working, I would like to add similar logic to the
> BrokenLinks link checker.
Look into ExecutorService and Executors in java.util.concurrency. They 
have exactly what you want.

<http://docs.oracle.com/javase/6/docs/api/index.html?java/util/concurrent/ExecutorService.html>

<http://docs.oracle.com/javase/6/docs/api/index.html?java/util/concurrent/Executors.html>

The idea is that you submit jobs to the ExecutorService (which is 
basically some sort of Thread Pool), and you can wait for the "Future" 
result of those jobs.

You might even consider turning your BookStoreProbe into a Callable:

<http://docs.oracle.com/javase/6/docs/api/index.html?java/util/concurrent/Callable.html>


More useful things in package summary:
<http://docs.oracle.com/javase/6/docs/api/index.html?java/util/concurrent/package-summary.html>

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Thread question Roedy Green <see_website@mindprod.com.invalid> - 2011-11-30 01:31 -0800
  Re: Thread question Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-11-30 01:48 -0800
  Re: Thread question Roedy Green <see_website@mindprod.com.invalid> - 2011-11-30 02:32 -0800
    Re: Thread question Roedy Green <see_website@mindprod.com.invalid> - 2011-11-30 02:48 -0800
    Re: Thread question Patricia Shanahan <pats@acm.org> - 2011-11-30 03:11 -0800
      Re: Thread question Paul Cager <paul.cager@googlemail.com> - 2011-11-30 07:10 -0800
        Re: Thread question Patricia Shanahan <pats@acm.org> - 2011-11-30 09:34 -0800
    Re: Thread question Roedy Green <see_website@mindprod.com.invalid> - 2011-11-30 06:10 -0800
      Re: Thread question markspace <-@.> - 2011-11-30 06:13 -0800
      Re: Thread question Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-11-30 11:53 -0800
  Re: Thread question Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-30 07:28 -0500
    Re: Thread question markspace <-@.> - 2011-11-30 05:30 -0800
      Re: Thread question Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-30 21:04 -0500
        Re: Thread question markspace <-@.> - 2011-11-30 18:28 -0800
  Re: Thread question markspace <-@.> - 2011-11-30 05:50 -0800
    Re: Thread question markspace <-@.> - 2011-11-30 06:04 -0800
  Re: Thread question Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-11-30 11:48 -0800
  Re: Thread question Roedy Green <see_website@mindprod.com.invalid> - 2011-11-30 13:23 -0800

csiph-web