Results 1 to 2 of 2
  1. #1
    paul is offline Member
    Join Date
    Jul 2007
    Posts
    26
    Rep Power
    0

    Default How can I set a time out on the loading process

    My program downloads webpages.
    It works fine as long as the url is valid.
    If the url is not valid it waits forever.
    How can I set a time out on the loading process?

    Java Code:
          try {
            URL pageUrl = new URL(currentUrl);
            BufferedReader reader = new BufferedReader(
            new InputStreamReader(pageUrl.openStream() ) );
            String line;
            StringBuffer pageBuffer = new StringBuffer();
            while ( (line = reader.readLine() ) != null ) {
              pageBuffer.append( line );
            }
            String fetchedPage = pageBuffer.toString();
          }
          catch (Exception e) {
          }
    Thanks

  2. #2
    coco is offline Member
    Join Date
    Jul 2007
    Posts
    39
    Rep Power
    0

    Default

    First...let me state the obvious...there is more than one way to do this. Of course..it all depends on what you want to achieve in the end.

    First solution.
    You can use threads. where you initiate the thread to open a web page...and then interrupt it (kill it) when a specified time has elapsed.

    Second Solution.
    You can make use of javax.swing.Timer, and schedule a delay before stopping the execution.

    I am sure that there are other ways to do this.
    Greetings.

Similar Threads

  1. i need help in http process
    By sureshjava in forum New To Java
    Replies: 0
    Last Post: 01-29-2008, 05:56 AM
  2. How to get variable values at runtime in another process
    By murali_java in forum Advanced Java
    Replies: 0
    Last Post: 11-02-2007, 09:03 AM
  3. Business Process Visual ARCHITECT 2.1
    By levent in forum Java Software
    Replies: 0
    Last Post: 08-04-2007, 08:49 PM
  4. Linux process from java
    By Ed in forum New To Java
    Replies: 2
    Last Post: 07-04-2007, 06:03 AM
  5. Business Process Visual ARCHITECT 2.0 SP2
    By levent in forum Java Software
    Replies: 0
    Last Post: 05-15-2007, 06:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •