URL class heavy on COU usage

From: jmm-list-gn (jmm-list.AXSPAMGN_at_sohnen-moe.com)
Date: 09/24/04


Date: Thu, 23 Sep 2004 23:07:33 -0700

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)


Relevant Pages

  • Re: High CPU Usage
    ... The remoting - in two places it ... The high CPU usage does not seem to be directly ... controls on each page is determined at runtime from the database. ... single shared connection was still available, ...
    (microsoft.public.dotnet.framework.aspnet)
  • 100 % CPU Usage on internet connectivety
    ... I use a wireless landphone connection to connect to internet. ... consuming about 90-95% of the CPU Usage. ... By the way I am using symantec anti virus corporate edition 8. ...
    (microsoft.public.win2000.general)
  • Re: [PHP] Command-line PHP script CPU usage goes sky-high, stays there--why?
    ... run indefinitely with a predictable CPU usage and memory footprint. ... connections, processes incoming data, stores results in a MySQL ... years on an Xserve dual-G5 2GHz w/ OS X Server 10.4.11). ... One question about the "listener" program, does it maintain a connection to the DB or does it ...
    (php.general)
  • 100 % CPU Usage on internet connectivety
    ... I use a wireless landphone connection to connect to internet. ... consuming about 90-95% of the CPU Usage. ... By the way I am using symantec anti virus corporate edition 8. ...
    (microsoft.public.win2000.networking)
  • 100 % CPU Usage on internet connectivety
    ... I use a wireless landphone connection to connect to internet. ... consuming about 90-95% of the CPU Usage. ... By the way I am using symantec anti virus corporate edition 8. ...
    (microsoft.public.win2000.advanced_server)