URL.openStream() very slow....

I got a strange problem with URL (Java 1.6-07):

URL.openStream() is deadly slow… like if it was loading the whole file somewhere before returning the stream.

the problem is that for a big file >1MB my progressbar is stuck at 0 percent then suddently goes 100% and I dont find that is very user friendly.

inded URLConnection.openStream() wich work the same is slow too.

setCache(false) doesn’t help too

it work well with the MS jvm …

I think that I will end using a tcp socket and simulate the HTTP GET as I already know it work well, but before, I would like to know if you have any better/shorter ideas ??

I haven’t encountered this behaviour and I don’t use the ms jvm at all.

I suppose you can try using http://java.sun.com/j2se/1.4.2/docs/api/java/net/URLConnection.html

do you have any code to reproduce?

I already use this one : URL.openConnection() return an URLConnection

this is not related to the ms jvm (I was just saying this one works fine), the problem happen with Java 1.6-07 .

basically anycode that get a file from an applet using URL I will try to provide a simple test case but for exemple something like this in an Applet:


public void start()
{
try
{
URL url=new URL(getCodeBase() +"/BIGFILE.3DS"); //like a 1MB to 10MB file
URLConnection uc   = url.openConnection();
InputStream is= uc.getInputStream(); //here it hang as if it was loading the whole file
//some time later you are here and the inputstream is became very fast.....
is.read();
}
catch(Exception e)
{
 e.printStackTrace();
}
}

my problem is that I want to monitor the file loading

you could just slow it down to make it look like it is loading.

but what is wrong with a huge jump. games do it all of the time. 100% jump is pretty big, however they will just be happy for the load to be done!

this is just not smooth and not professional… and while it is stuck at 0% look like if it is bugged and users may quit.

I know this was the case with all versions of the sun plugin when urlconnection.setusecache is set to true (the ms jvm didnt have this problem if I recall correctly):

http://www.java-gaming.org/index.php/topic,11472.msg90709.html#msg90709
http://www.java-gaming.org/index.php/topic,11269.msg90225.html#msg90225
http://www.java-gaming.org/index.php/topic,19400.msg155096.html#msg155096

Maybe they screwed up even more in the latest release which makes this behaviour always present? :-\

edit:
Maybe a workaround could be what you suggested, by doing it yourself… the only problem is that the jvm wont cache files that way (not without signing the applet and doing that yourself too), something you clearly want for big files and applets. Maybe you can trick the jvm in downloading the file yourself in memory (showing progress), and then establishing an urlconnection to a file in memory with setusecache(true) or something like that…

Try URL.openConnection().getInputStream()? or a new thread

hey thanks Thijs ! I didn’t know that you already looked at this issue

EDIT:

@Renoria : inded I use a separated thread, the Applet is not stuck : the problem is just that the progressbar is wrong

I did a try with a tiny HTTP client I just wrote, this work fine even throught an http proxy but I fall on another problem… I have to hardcode the proxy setting no way to cleanly find those settings … finally I think that I will use the buggy URL classes and play with some animated gif :frowning:

I have used 1.6.0_07 for months, and never experienced such problems with downloading…

http://www.indiespot.net/files/spooky_applet.html (applet sourcecode available on that page)

Try for yourself, it works for me…?

thanks a lot, this one works fine for me ??? I will look if I can find whats wrong in mine… thks !

You could also make a fake progress bar up to 50% - 70% than it completes when the download is over. It would look better but wouldn’t fix anything…

hum… not sure anymore… seems that it only works very well on reload, at the first load download only start after 20 second of uptime… that’s boring :-\

I do my test with a 2MB file size and it take age to start downloading… up to one minute

Remember that all JRE plugins before u10 were crap.

Do yourself a favor and upgrade :slight_smile: