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.
Brian Cole wrote:Nothing obvious jumps out at me. What happens if you replace
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.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com