Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (491)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  URL.openStream() very slow....  (Read 2993 times)
0 Members and 1 Guest are viewing this topic.
Offline DzzD
« Posted 2009-04-15 23:29:51 »

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  ??

Offline Mr_Light

Senior Member




shiny.


« Reply #1 - Posted 2009-04-16 00:02:37 »

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?

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline DzzD
« Reply #2 - Posted 2009-04-16 00:21:01 »

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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
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

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #3 - Posted 2009-04-16 07:38:42 »

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!
Offline DzzD
« Reply #4 - Posted 2009-04-16 08:26:08 »

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.

Offline thijs

Junior Member




Lava games rock!


« Reply #5 - Posted 2009-04-16 08:26:26 »

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.

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/topics/reading-files-from-an-applet/11472/msg/90709/view.html#msg90709
http://www.java-gaming.org/topics/jogl-applet-security/11269/msg/90225/view.html#msg90225
http://www.java-gaming.org/topics/java-cache/19400/msg/155096/view.html#msg155096

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

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...

<a href="http://www.dzzd.net">3DzzD!</a>
<a href="http://www.arcazoid.com">Arcazoid!</a>
Offline Renoria

Junior Member




...


« Reply #6 - Posted 2009-04-16 10:57:35 »

Try URL.openConnection().getInputStream()? or a new thread
Offline DzzD
« Reply #7 - Posted 2009-04-16 14:22:03 »

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/topics/reading-files-from-an-applet/11472/msg/90709/view.html#msg90709
http://www.java-gaming.org/topics/jogl-applet-security/11269/msg/90225/view.html#msg90225
http://www.java-gaming.org/topics/java-cache/19400/msg/155096/view.html#msg155096

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

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...

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 Sad ...

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 783
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #8 - Posted 2009-04-16 17:11:37 »

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...?

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline DzzD
« Reply #9 - Posted 2009-04-16 17:39:04 »

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  Huh I will look if I can find whats wrong in mine... thks !

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Gudradain
« Reply #10 - Posted 2009-04-16 17:50:17 »

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...
Offline DzzD
« Reply #11 - Posted 2009-04-16 18:18:39 »

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...?

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  Undecided

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

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 783
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #12 - Posted 2009-04-16 22:05:37 »

Remember that all JRE plugins before u10 were crap.

Do yourself a favor and upgrade Smiley

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (15 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (29 views)
2014-08-22 19:31:30

atombrot (41 views)
2014-08-19 09:29:53

Tekkerue (39 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (25 views)
2014-08-16 06:20:21

Tekkerue (36 views)
2014-08-16 06:12:11

Rayexar (72 views)
2014-08-11 02:49:23

BurntPizza (49 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!