Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

options for monitoring a long downloading task ?

 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • 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 ?
 
Winston Gutkowski
Bartender
Pie
Posts: 10417
63
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 10417
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • 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
 
Stephan van Hulst
Bartender
Pie
Posts: 5790
61
  • Mark post as helpful
  • send pies
  • 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
  • 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
Bartender
Pie
Posts: 5790
61
  • Mark post as helpful
  • send pies
  • 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
  • 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
    Bartender
    Pie
    Posts: 5790
    61
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Yeah, so you can just create a new SwingWorker and call the execute() method on that.
     
    Rob Spoor
    Sheriff
    Pie
    Posts: 20526
    54
    Chrome Eclipse IDE Java Windows
    • Mark post as helpful
    • send pies
    • 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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic