0

I have Applications that search page and get a specified number of links. Each link is retrieved by a separate thread. This Simple Code Do this:

    public class GetLinkThread implements Runnable {
    public int page;
    public GetLinkThread(int page) {
        this.page = page;
    }
    @Override
    public void run() {
        try {
            Parser.parseAndAddLinkToSet(page);//this method get links from sites and save to set
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

In parseAndAddLinkToSet(int page) method is String root = "www.example.com/" + page; so I only send the page number to be crawled for links.

And I run this:

ExecutorService executorService = Executors.newCachedThreadPool();
    for(int i = 1 ; i < 4 ; i++){//in this case I run 3 threads
        executorService.execute(new GetLinkThread(i));
    }
    executorService.shutdown();
    executorService.awaitTermination(1, TimeUnit.HOURS);

I want to make progressbar which when downloading links will show the link that is currently being downloaded by the given thread. I can make progressBar but i don't know how make progressBar which run in background and with another threads.

So my question is, how can I add now a progressBar to my application? ProgressBar which is running when i crawling page and display current page?

JavaCoder
  • 135
  • 2
  • 8
  • What would the progress bar be measuring the progress of? Why would it be a single progress bar when you have a cached thread pool which would be running multiple threads in parallel? – jewelsea Sep 13 '17 at 22:25
  • There are examples on linking progress bars to tasks and services in the answer to this question: [How to reset progress indicator between tasks in JavaFX2?](https://stackoverflow.com/questions/16368793/how-to-reset-progress-indicator-between-tasks-in-javafx2). Though I'm that answer is not exactly representative of what you are trying to do, studying it may help you to better understand your problem and its potential solution. Read up on [JavaFX concurrency](https://docs.oracle.com/javase/8/javafx/interoperability-tutorial/concurrency.htm). – jewelsea Sep 13 '17 at 22:26

0 Answers0