Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

URL class heavy on COU usage
Hello,
Java v1.4.2_05.
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%
greatly slowing the functioning of other programs. When the connection
closes, the usage drops back to normal.
Is this expected? A possible problem in the JVM?
Is there an alternate, low CPU usage, way of connecting?

Here is the code that pegs the CPU meter (less the exception code):

URL url;
String url_str = protocol + "://" + hostname
+ "/" + prefix + "/" + service;

// Create new URL and connect
//
// Let Sun's JSSE to deal with SSL
java.security.Security.addProvider(
new com.sun.net.ssl.internal.ssl.Provider());
System.getProperties().put("java.protocol.handler.pkgs",
"com.sun.net.ssl.internal.www.protocol");
url = new URL(url_str);
HttpsURLConnection connection =
(HttpsURLConnection) url.openConnection();

// Setup HTTP POST parameters
connection.setDoOutput (true);
connection.setDoInput  (true);
connection.setUseCaches(true);

// Get POST data from input StringBuffer containing an XML document
//
String queryString = XmlIn.toString();

// POST data
//
System.out.println("...sending request..."); System.out.flush();
OutputStream out = connection.getOutputStream();
out.write(queryString.getBytes());
out.close();

// get data from URL and return the XML doc as a StringBuffer
//
String data = "";
data = readURLConnection(connection);

// Data is saved and the function exits here closing the connection.

--
jmm dash list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)

Report this thread to moderator Post Follow-up to this message
Old Post
jmm-list-gn
09-24-04 09:00 AM


Re: URL class heavy on COU usage
jmm-list-gn <jmm-list.AXSPAMGN@sohnen-moe.com> wrote in message news:<0qWdnXdwQ6w7JM7cRVn-s
Q@giganews.com>...
> Hello,
>    Java v1.4.2_05.
>    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%
> greatly slowing the functioning of other programs. When the connection
> 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-   ><>

Report this thread to moderator Post Follow-up to this message
Old Post
FISH
09-24-04 09:03 PM


Re: URL class heavy on COU usage
FISH wrote: 
>
> 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)
> 
>
> 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.

--
jmm dash list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)

Report this thread to moderator Post Follow-up to this message
Old Post
jmm-list-gn
09-24-04 09:03 PM


Re: URL class heavy on COU usage
"jmm-list-gn" <jmm-list.AXSPAMGN@sohnen-moe.com> schreef in bericht
news:0qWdnXdwQ6w7JM7cRVn-sQ@giganews.com...
> Hello,
>    Java v1.4.2_05.
>    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%
> greatly slowing the functioning of other programs. When the connection
> 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.



Report this thread to moderator Post Follow-up to this message
Old Post
Boudewijn Dijkstra
09-25-04 01:57 AM


Re: URL class heavy on COU usage
Boudewijn Dijkstra wrote: 
>
> 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?

--
jmm dash list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)

Report this thread to moderator Post Follow-up to this message
Old Post
jmm-list-gn
09-25-04 01:57 AM


Re: URL class heavy on COU usage
"jmm-list-gn" <jmm-list.AXSPAMGN@sohnen-moe.com> schreef in bericht
news:IsidnaBhcZDKLcncRVn-oA@giganews.com...
> Boudewijn Dijkstra wrote: 
>    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?

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);



Report this thread to moderator Post Follow-up to this message
Old Post
Boudewijn Dijkstra
09-25-04 02:00 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Java Help archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:23 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.