Win a copy of Practice Tests for OCP Java 17 Certification Exam (1Z0-829) this week in the OCPJP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Thread missed in the middle with ThreadPoolExecutor

Ranch Hand
Posts: 91
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ppl,

I have a ThreadPoolExecutor, which spawns worker threads to download binaries from an url.

URLDownloadTask is just a runnable URL downloader and print the MD5 of the downloaded file to the log. Now my problem is when I see 200 distinct urls (through the variable i), I see the task count as 200 in line x and 198 or 199 (differs with every execution, but definitely less than 200) at line y. Also only 198 or 199 urls are being downloaded. And I see the missing url's download is initiated and not completed. And as the documentation for .getTaskCount() says

Returns the approximate total number of tasks that have been scheduled for execution. Because the states of tasks and threads may change dynamically during computation, the returned value is only an approximation, but one that does not ever decrease across successive calls.

I am puzzled how can the count decrease in my case. And all the urls are active and I even checked the missing url manually through browser. This occurs with whatever number of urls I mean. For example with 246 distinct urls, I see only 244 or 243 but definitely less than 246.

Please provide your suggestions in this case.
Their achilles heel is the noogie! Give them noogies tiny ad!
Free, earth friendly heat - from the CodeRanch trailboss
    Bookmark Topic Watch Topic
  • New Topic