
Signature
jmm dash list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)
> Hello,
> Java v1.4.2_05.
[quoted text clipped - 3 lines]
> closes, the usage drops back to normal.
> Is this expected? A possible problem in the JVM?
Which JVM would that be? ;-)
> Is there an alternate, low CPU usage, way of connecting?
Almost certainly, the fault is in your code. You don't specify what
the readURLConnection method does. It's possible there's some bad logic
in there controlling a loop. That's the most likely possibility. SSL
is another candidate, although I'd rule out your own code first, before
you start to blame Sun's.
-FISH- ><
jmm-list-gn - 24 Sep 2004 17:46 GMT
>> Is this expected? A possible problem in the JVM?
>
> Which JVM would that be? ;-)
java version "1.4.2_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_05-b04)
Java HotSpot(TM) Client VM (build 1.4.2_05-b04, mixed mode)
>> Is there an alternate, low CPU usage, way of connecting?
>
> Almost certainly, the fault is in your code. You don't specify what
> the readURLConnection method does.
Oops. Here it is:
int letter;
reader = new BufferedReader(new
InputStreamReader(uc.getInputStream()));
while (-1 != (letter = reader.read()))
buffer.append((char) letter);
reader.close();
I'd have thought that read() would block until there was actual input.

Signature
jmm dash list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)
> Hello,
> Java v1.4.2_05.
[quoted text clipped - 3 lines]
> closes, the usage drops back to normal.
> Is this expected? A possible problem in the JVM?
Any unbuffered system stream is likely to draw 100% CPU, period.
jmm-list-gn - 25 Sep 2004 00:40 GMT
>> I am using the URL and HttpsURLConnection classes in a program. As soon
>>as the openConnection() method is called, the CPU usage goes to 100%
[quoted text clipped - 3 lines]
>
> Any unbuffered system stream is likely to draw 100% CPU, period.
Hmm, yes. Most of the time is spent in the HttpsURLConnection methods.
readURLConnection() is a buffered stream.
So your implication is that unbuffered streams are used in the http and
URL classes. Is there a way to use buffered streams?

Signature
jmm dash list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)
Boudewijn Dijkstra - 25 Sep 2004 11:43 GMT
> >> I am using the URL and HttpsURLConnection classes in a program. As soon
> >>as the openConnection() method is called, the CPU usage goes to 100%
[quoted text clipped - 8 lines]
> So your implication is that unbuffered streams are used in the http and
> URL classes. Is there a way to use buffered streams?
You can buffer an arbitrary stream by wrapping it into a new
java.io.BufferedXxxputStream, like so:
myBufferedInput = new BufferedInputStream(myInput);
or
myBufferedOutput = new BufferedOutputStream(myOutput);
You can then use the new stream in the same way as the old one, or even use
the same reference:
myXxxput = new BufferedXxxputStream(myXxxput);