This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Java in General and the fly likes options for monitoring a long downloading task ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "options for monitoring a long downloading task ?" Watch "options for monitoring a long downloading task ?" New topic
Author

options for monitoring a long downloading task ?

naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 692

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 ?


The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8661
    
  23

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

It depends. Is the download process a Java one?

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 692

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

Joined: Aug 22, 2010
Posts: 3719
    
  61

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

Joined: Mar 17, 2011
Posts: 8661
    
  23

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

Joined: Sep 20, 2010
Posts: 4087
    
  18

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 mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 692

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

Joined: Sep 20, 2010
Posts: 4087
    
  18

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

Joined: Jul 03, 2011
Posts: 692

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

    Joined: Sep 20, 2010
    Posts: 4087
        
      18

    Yeah, so you can just create a new SwingWorker and call the execute() method on that.
    Rob Spoor
    Sheriff

    Joined: Oct 27, 2005
    Posts: 20128
        
      30

    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.


    SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
    How To Ask Questions How To Answer Questions
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: options for monitoring a long downloading task ?
     
    It's not a secret anymore!