File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Slow Swing FTP Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Slow Swing FTP Problem" Watch "Slow Swing FTP Problem" New topic
Author

Slow Swing FTP Problem

Jaz Chana
Ranch Hand

Joined: Feb 19, 2008
Posts: 34
Hi Guys,

I'm trying to create a swing gui to ftp a file onto a server. I'm using the apache commons package to achieve this. I'm using the following code;



Standalone it works fine, no problems. However when I try to run it through a swing gui it just seems to slow right down. I've tried to call the above code in several different ways. For example, by calling it directly from an actionListener attached to a button, and then by placing this in the doInBackround() method of a swing worker thread, then calling the class's execute method. Wherever I call it, there is still this slowdown in execution. Using the sys outs above I see there is a huge pause between the "store file" and "file stored. Logout" outputs. Then I thought it could be a memory issue, so I decided to increase the JVM heap using Xms and Xms runtime parameters. But still no difference!

I cant work out why it takes so long to ftp from a swing gui when the same piece of code standalone works perfectly fine. Does anyone have any suggestions or clues as to why this is happening? I'm not a swing expert, so I'm at a loss.

Any help would be greatly appreciated.

Thanks
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
Nothing obvious jumps out at me. What happens if you replace
  • new FileInputStream(sourceFile.getAbsolutePath())
  • with
  • new BufferedInputStream(new FileInputStream(sourceFile.getAbsolutePath()))
  • Does it help any?

    Also, this is probably unrelated to your performance problem, but does the storeFile() method close the stream? If not, you should close it yourself.


    bitguru blog
    Jaz Chana
    Ranch Hand

    Joined: Feb 19, 2008
    Posts: 34
    Brian Cole wrote:Nothing obvious jumps out at me. What happens if you replace
  • new FileInputStream(sourceFile.getAbsolutePath())
  • with
  • new BufferedInputStream(new FileInputStream(sourceFile.getAbsolutePath()))
  • Does it help any?

    Also, this is probably unrelated to your performance problem, but does the storeFile() method close the stream? If not, you should close it yourself.


    I've just had a very weird result. I tried to uplod to the FTP server from an external network via a vpn connection and suddenly its a hell of alot faster, in both cases!! I would have said this isn't a swing related problem, if it wasn't for the fact that the standalone app works perfectly fine in both inside and outside the network. Only the swing app slows down the upload inside the network. I will try the your suggestions when I get back on the network. Thanks for the heads up on the FileInputStream.
     
     
    subject: Slow Swing FTP Problem