Win a copy of Java Persistence with Spring Data and Hibernate this week in the Spring 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 ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

how can I update onprogressupdate in asynctask using ExecutorService and Future Interface

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've research a bit about speeding up the application I'm working on. It is a network/port scanner and originally it did everything on a single thread using Asynctask. But I wanted to speed it up. So I looked at Runnable and Callable interface. Since I need to return something from the thread (if there's another way please let me know) I settled for Callable interface. My problem is that I can't figure out how to get the results from the Callable class and update the Asynctask onProgressUpdate() method. The IpScanCallable class returns data of type Node. Which is an object that holds information about especific node eg: ip, mac. I tried publishUpdate(node) but that didn't work. Is there any way of achieving this. Thanks
AsyncTask is at the buttom

IpScanCallable
 
Bartender
Posts: 7488
171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While you didn't say  what "that didn't work" means, exactly (please always TellTheDetails), what jumps out is that you're calling publishProgress with no parameters - so it can't possibly provide results. Either pass the Future to onProgressUpdate and handle it there, or remove the Callable/Future stuff entirely and run AsyncTask in parallel via executeOnExecutor().

As an aside, I took the liberty of removing the GUI code, since that doesn't have anything to do with the problem at hand.
 
I knew that guy would be trouble! Thanks tiny ad!
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic