Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8447243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:08:12+00:00 2026-06-10T10:08:12+00:00

Some times work throuw the proxy server and reading prom buffer content my program

  • 0

Some times work throuw the proxy server and reading prom buffer content my program to think so more time… until i close them. How set program code that from some seconds if do not have any answer from server to take another server?

URL url = new URL(linkCar);
String your_proxy_host = new String(proxys.getValueAt(xProxy, 1).toString());
int your_proxy_port = Integer.parseInt(proxys.getValueAt(xProxy, 2).toString());
Proxy proxy = null;
//  System.out.println(proxys.getValueAt(xProxy, 3).toString());
//  if (proxys.getValueAt(xProxy, 3).toString().indexOf("HTTP") > 0)
//  {
proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(your_proxy_host, your_proxy_port));
//  } else {
//  proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(your_proxy_host, your_proxy_port));
//  }

HttpURLConnection connection = (HttpURLConnection)url.openConnection(proxy);
connection.setConnectTimeout(1000);
connection.connect();

String line = null;
StringBuffer buffer_page = new StringBuffer();
BufferedReader buffer_input = new BufferedReader(new InputStreamReader(connection.getInputStream(),"cp1251")); 
int cc = 0;

//this is thinking place!!!
while ((line = buffer_input.readLine()) != null && cc < 7000) {
   buffer_page.append(line);
   cc++;
}

doc = Jsoup.parse(String.valueOf(buffer_page));
connection.disconnect();

i tried to use counter but it not work… What exception i can use to catch this situation by my control?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T10:08:13+00:00Added an answer on June 10, 2026 at 10:08 am

    You need to use URLConnection.setReadTimeout. From the specification,

    Sets the read timeout to a specified timeout, in milliseconds. A non-zero value specifies the timeout when reading from Input stream when a connection is established to a resource. If the timeout expires before there is data available for read, a java.net.SocketTimeoutException is raised. A timeout of zero is interpreted as an infinite timeout.

    As you can see, reads that time-out will throw SocketTimeoutException, which you can catch appropriately, e.g.

    try (BufferedReader buffer_input = new BufferedReader(
             new InputStreamReader(connection.getInputStream(), "cp1251"))) {
      String line;
      while ((line = buffer_input.readLine()) != null) {
        buffer_page.append(line);
      }
    } catch (SocketTimeoutException ex) {
      /* handle time-out */
    }
    

    Note that you need to be careful when using readLine as above — this will strip all \r and \n from the input.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my java-written application being killed after some time of work. Java application
I have been working on this for some time. The script does work and
I work at a site that passed through some face lifts. In time the
I work with C# 99% of the time. However, I'm having to update some
I just got my ssl certificate to work for the first time. For some
I have a Runnable implementation that does some work which might take some time
Main thread of application is doing some work. There also exists a timer, which
Many times I work with optimized code (sometimes even involving vectorized loops), which contain
Cannot read records after inserting to google calendar. Some time letter, records are read.
I use ASP.Net and a static WebMethod / PageMethod to do some async work.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.