- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有时,我的程序会通过代理服务器并读取舞会缓冲区内容来思考更多时间......直到我关闭它们。如何设置程序代码,在几秒钟内如果没有来自服务器的任何答复,则采取另一台服务器?
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();
我尝试使用计数器,但它不起作用...我可以使用什么异常来通过我的控制捕获这种情况?
最佳答案
您需要使用URLConnection.setReadTimeout
。从规范来看,
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.
如您所见,读取超时将抛出 SocketTimeoutException
,您可以适本地捕获,例如
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 */
}
请注意,如上所述使用 readLine
时需要小心 - 这将从输入中删除所有 \r
和 \n
.
关于java - 代理人。思考过程。我怎样才能杀死他们?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12151370/
Transformer 模型是 AI 系统的基础。已经有了数不清的关于 "Transformer 如何工作" 的核心结构图表。 但是这些图表没有提供任何直观的计算该
我有一个很大的索引定义,索引需要很长时间。我怀疑主要问题是由生成的许多 LEFT OUTER JOIN 引起的。 我看到了 this question ,但找不到有关使用 source: :query
我目前是FP的学生。当我查看不同函数式语言提供的不同语法时,我在 Elm 示例代码中遇到了一个模式。我对此很好奇。 这是示例代码 myList = [{foo = "bar1"},{foo = "ba
我正在尝试使用 HTML 和 CSS 进行响应式设计,这是我的问题: 如果你只调整窗口大小,布局适合,如果你只缩放,布局再次适合,我没有问题,但是如果在调整窗口大小时缩放,布局会中断一点。 找到有关此
我正在寻找模型项目。项目属于公司,因此列表中的所有项目都可以附加相同的公司。结果列表示例: CompanyA - ProjectA CompanyA - ProjectO CompanyA - Pro
我使用的编程语言是 Java。我一直在过渡到有些困难的 C++。 “难懂”不在学习中,更多的是“用 C++ 思考”。 我看到很多人说你应该先学习C(我在技术上已经知道了),然后我看到有人说不要跳过C直
我正在整理一个存储库类型的 rails 3 站点。 我安装了 Thinking Sphinx 并在我的网站上工作,因为我可以输入类似 localhost:3000/articles?search=te
我正在使用 sphinx 搜索 2 个模型及其关联。我正在使用增量索引。在开发模式 (Ubuntu) 下,我的开发箱上一切正常。但是,在暂存盒生产环境中,当我创建新记录时,我需要再次构建索引以使新创建
我已将 delta 列添加到我的表中: class AddDeltaIndexToCimgs < ActiveRecord::Migration def change add_column
我安装了think sphinx,运行 rake ts:index 后,无法配置开发文件。文件已创建,但它是空的。 Generating configuration to /Users/lexi87/
这很奇怪。我有 3 个模型(A、B、C)。当 crontab 运行它时,我们工作得很好。 最近,我在为模型 A 索引新条目时遇到问题。 当我手动调用 rake ts:index RAILS_ENV=p
如果我的搜索包含类别(外键)和可选文本,我是否应该使用 Thinking sphinx 来“搜索”未提交搜索字符串(仅提交类别)的地方? 最佳答案 这实际上取决于您的用例。举例来说,假设您有博客文章,
以下代码来自Thinking in C++。作者提到“由于 operator[] 是内联的,您可以使用这种方法来保证不会发生数组边界违规,然后删除传送代码的 require()。”这里指的是内联函数的
这是我确定的: Delta 索引在开发中运行良好 当我推送到生产服务器时,Delta 索引不起作用,并且 searchd.log 中没有记录任何操作 我正在运行 Phusion Passenger,并
最近接了一个项目,性质比较独特,想请教大家一些建议。 我分别使用 asp.net/SQL Server 和 php/mysql。我从来没有把它们混为一谈。但是,我当前的项目要求我在使用 SQL Ser
我目前正忙于学习 Ruby 和 Rails,并且由于我有基于 C 语言的背景,Ruby 的一些概念是新的并且有些陌生。对我来说特别具有挑战性的是适应处理常见问题的“Ruby 方式”,因此我经常发现自己
每次我尝试在 Mac OSX Snow Leopard 上运行带有 Rails 3 的 Sphinx 2.0.1 时,我都会收到以下错误: Failed to start searchd daemon
我正在努力提高我的 TDD/OO 技能,但每次我尝试使用 TDD 来影响设计时,我都会遇到从哪里开始的障碍。 这是我的用例/故事: Identify a subset of clients that
得到这个 HTML: Un Deux Trois mother 在页面中,但是 children,select 和 input 都是动态生成的 试着用类似
我以前使用过 javascript,但现在我开始使用 angularjs,但我对如何做基本的事情感到困惑。 例如:在 JavaScript 中: //here is how i create a c
我是一名优秀的程序员,十分优秀!