• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

options for monitoring a long downloading task ?

 
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have a situation in my code
where i need to monitor a long running download of a file
i can use swing workers but the problem with them is you can use them just once not twice or more , so this is definetely not gonna work in my case
if you were in my situation what you would be doing ?
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

naved momin wrote:if you were in my situation what you would be doing ?


It depends. Is the download process a Java one?

Winston
 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Winston Gutkowski wrote:

naved momin wrote:if you were in my situation what you would be doing ?


It depends. Is the download process a Java one?

Winston


ya
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

naved momin wrote:... i can use swing workers but the problem with them is you can use them just once not twice or more...


Why couldn't you reuse SwingWorkers? In my application, several instances of SwingWorker run at once without any problems.
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

naved momin wrote:

Winston Gutkowski wrote:It depends. Is the download process a Java one?

ya


I'm not familiar with SwingWorker, so I can't comment, but I think I'd probably just make the download process a java.util.Observable, and have whatever needs to check on it implement java.util.Observer.
I suspect there are also more "GUI"-specific solutions, but Observable/Observer has always seemed very straightforward to me.

Winston
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will definitely want to use a SwingWorker. It's perfectly tailored for this sort of thing.

What exactly is the problem you're experiencing with them?
 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:You will definitely want to use a SwingWorker. It's perfectly tailored for this sort of thing.

What exactly is the problem you're experiencing with them?


the problem with swing worker is
we can call its execute() only once ..i know that from javadocs and also i have tried it execute 1st time but not 2nd time
means we cannot create multiple instance of swingworker i suppose ?
 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What makes you think you can't create multiple instances? The constructor and execute() method are two different things. Just create a new worker for each download.
 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:What makes you think you can't create multiple instances? The constructor and execute() method are two different things. Just create a new worker for each download.


this is straight from java api
  • SwingWorker is only designed to be executed once. Executing a SwingWorker more than once will not result in invoking the doInBackground method twice.
  •  
    Stephan van Hulst
    Saloon Keeper
    Posts: 15510
    363
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Yeah, so you can just create a new SwingWorker and call the execute() method on that.
     
    Sheriff
    Posts: 22783
    131
    Eclipse IDE Spring VI Editor Chrome Java Windows
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Naved is right; I experienced that myself. SwingWorker has a state which goes from PENDING to STARTED to DONE, but never back to PENDING or STARTED.
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic