[Java技术] What does the exception "java.net.SocketException: Connection reset by peer" mean? How can this be avoided?
It usually happens when the connection was reset by the peer -- that is, when the client unexpectedly closed the socket. This happens when the user clicks "stop", or "reload", or "back", or enters a new URL, or closes his Internet connection, while a resource is still being downloaded (before your server gets to close its socket). This is normal behavior and you shouldn't worry about it.
The server is reporting "connection reset by peer" in the middle of a request. That means one of the following things:
- The browser started a request and the user pressed STOP.
- The browser started an request in one frame and JavaScript on another frame told it to go somewhere else (which has the same effect as a user pressing STOP).
- You have a meta refresh reload someplace that is firing so fast that the previous request hasn't had a chance to complete yet. The five second periodicity makes me pretty suspicious of this.
- You have some network component in between (a router or proxy) that is misbehaving.
- You have some completely separate connection attempts going on that are disobeying the HTTP protocol (such as doing a telnet connection to port 8080 and then disconnecting).
自从JDK1.5以后java.net.URLConnection加入了setConnectTimeout(int timeout),但是也有办法在JDK1.5以前获得这个功能。
Adding Socket Timeout to java.net.URLConnection
HTTPClient Version 0.3-3
The Jakarta Commons HttpClient
另外,可以通过以下两个语句来设置相应的超时:
System.setProperty("sun.net.client.defaultConnectTimeout", 连接超时毫秒数);
System.setProperty("sun.net.client.defaultReadTimeout", 读数据超时毫秒数);
参见:http://java.sun.com/j2se/1.4.2/docs/guide/net/properties.html
google:set Timeout on URLConnection
Well performing NIO code is a Good Thing. But getting details of how to do it right is difficult. The examples supplied with the JDK are complete noddy. There's a link on Sun's site to an example but that has a race condition. O'Reilly's NIO book cops out on how to use Selector properly. The thing that could make that book useful.
凭什么要普通网站面向搜索引擎设计?凭什么要普通网站面向搜索引擎优化?搜索引擎应该要面向网站才对!我们只要做好自己的网站就行。
据乐观统计再优秀的搜索引擎也只能索引、搜索整个互联网的1/4的信息内容——这个根本就不容置疑。因为,网站的结构多种多样、网站的文件格式也千奇百怪、用的技术也是无穷无尽。例如,大多数地网站都使用Javascript,而google对Javascript的支持就有限,它无法象IE那样让Javascript执行后看到的网页模样;google还对表单(form)提交无能为力,而互联网上的很多网站就是通过表单提交来完成获得信息的;还有很多网页是嵌套的frame、iframe等等——这样使得再优秀的搜索引擎也无法索引全部的互联网信息。另外,整个互联网的内容如此博大,全部更新一次要花去很多时间,索引更新周期太长。但是,互联网上的各行业信息越来越专业,网站也越来越专业,人们需要更加专业的信息,更加有用的信息。有很多网站依赖google,baidu等搜索引擎来搜索自己的站点信息,这样搜索的信息当然不完整不完全,甚至根本就搜索不到自己的站点。
作者:Scott Ambler著,乐林峰 译 本文选自:www.umlchina.com
我们期待自己成为一个优秀的软件模型设计者,但是,要怎样做,又从哪里开始呢?
将下列原则应用到你的软件工程中,你会获得立杆见影的成果。
[http://www.javaalmanac.com] - Java开发者年鉴一书的在线版本. 要想快速查到某种Java技巧的用法及示例代码, 这是一个不错的去处.
[http://www.onjava.com] - O'Reilly的Java网站. 每周都有新文章.
[http://java.sun.com] - 官方的Java开发者网站 - 每周都有新文章发表.
[http://www.developer.com/java] - 由Gamelan.com 维护的Java技术文章网站.
[http://www.java.net] - Sun公司维护的一个Java社区网站.
[http://www.builder.com] - Cnet的Builder.com网站 - 所有的技术文章, 以Java为主.
[http://www.ibm.com/developerworks/java] - IBM的Developerworks技术网站; 这是其中的Java技术主页.
[http://www.javaworld.com] - 最早的一个Java站点. 每周更新Java技术文章.
[http://www.devx.com/java] - DevX维护的一个Java技术文章网站.
[http://www.fawcette.com/javapro] - JavaPro在线杂志网站.
[http://www.sys-con.com/java] - Java Developers Journal的在线杂志网站.
[http://www.javadesktop.org] - 位于Java.net的一个Java桌面技术社区网站.
[http://www.theserverside.com] - 这是一个讨论所有Java服务器端技术的网站.
[http://www.jars.com] - 提供Java评论服务. 包括各种framework和应用程序.
[http://www.jguru.com] - 一个非常棒的采用Q&A形式的Java技术资源社区.
[http://www.javaranch.com] - 一个论坛,得到Java问题答案的地方,初学者的好去处。
[http://www.ibiblio.org/javafaq/javafaq.html] - comp.lang.java的FAQ站点 - 收集了来自comp.lang.java新闻组的问题和答案的分类目录.
http://java.sun.com/docs/books/tutorial/] - 来自SUN公司的官方Java指南 - 对于了解几乎所有的java技术特性非常有帮助.
http://www.javablogs.com] - 互联网上最活跃的一个Java Blog网站.
http://java.about.com/] - 来自About.com的Java新闻和技术文章网站.
Most web and enterprise Java applications can be split into three parts: a front end to talk to the user, a service layer to talk to back-end systems such as databases, and business logic in between. While it is now common practice to use frameworks for both front- and back-end requirements (e.g., Struts, Cocoon, Spring, Hibernate, JDO, and Entity Beans), there is no standard way of structuring business logic. Frameworks like EJB and Spring do this at a high level, but don't help us in organizing our code. Wouldn't it would be great if we could replace messy, tangled if...then statements with a framework that gave us the same benefits of configurability, readability, and reuse that we already enjoy in other areas? This article suggests using the Drools rules engine as a framework to solve the problem.
Mckoi SQL Database is an SQL (Structured Query Language) Database management system written for the JavaTM platform. Mckoi SQL Database is optimized to run as a client/server database server for multiple clients, however it can also be embedded in an application as a stand-alone database. It is highly multi-threaded and features an extendable object-oriented engine.
Mckoi SQL Database started as an internal project and has since evolved from its inception in 1998. The main goals of the project are a code base that is simple to maintain and extend, ease of use and administration, robustness, multiple concurrent access, and performance.
本文为转载文章. 阅读全文...
本文为转载文章. 阅读全文...
1. Overview
As the name implies, AMDD is the agile version of Model Driven Development (MDD). MDD is an approach to software development where extensive models are created before source code is written. A primary example of MDD is the Object Management Group (OMG)?s Model Driven Architecture (MDA) standard. With MDD a serial approach to development is often taken, MDD is quite popular with traditionalists, although as the RUP/EUP shows it is possible to take an iterative approach with MDD. The difference with AMDD is that instead of creating extensive models before writing source code you instead create agile models which are just barely good enough.
Figure 1 depicts a high-level lifecycle for AMDD for the release of a system. First, let?s start with how to read the diagram. Each box represents a development activity. The initial modeling activity includes two main sub-activities, initial requirements modeling and initial architecture modeling. These are done during cycle 0, cycle being another term for iteration. ?Cycle 0? is an XP term for the first iteration before you start into development cycles, which are iterations one and beyond (for that release). The other activities ? model storming, reviews, and implementation ? potentially occur during any cycle, including cycle 0. The time indicated in each box represents the length of an average session: perhaps you?ll model for a few minutes then code for several hours. I?ll discuss timing issues in more detail below.
[Java技术] Step into the J2EE architecture and process
Develop complete J2EE solutions with an eight-step cycle
Summary
The Java 2 Enterprise Edition (J2EE) Platform is defined by four key pieces: the specification, the reference implementation, the compatibility test suite, and the BluePrints program. BluePrints describes the best practices and design guidelines for a distributed component architecture. This article introduces an eight-step J2EE development methodology based on the Rational Unified Process and the BluePrints sample application. By reading this article, you will better understand many important J2EE architecture topics, and be able to apply that knowledge to extend and modify this simple methodology to solve your special business problems. (3,600 words; September 28, 2001)
原链接地址
1. Make sure that SQL Server is set to mixed authentication. To do this, open enterprise manager, right click on server/properties; go to security tab and select SQL Server and Windows Authentication. Apparently, the driver from Microsoft cannot handle windows integrated authentication.
2. Keeping the server properties dialog up, go to the general tab and push the network configuration button. Enable TCP/IP (it is disabled by default). If you wish, press properties to change the default port (1433).
3. Add an SQL Server login account (NOT a WINDOWS account (see 1)). You can also use your sa account, but I don't recommend it.
4. Use the login setup in step 3.
Some final notes:
(1) I've seen ads for third party drivers that can use Windows integrated authentication. Try one if you need this feature.
(2) One responder suggested telneting to port 1433 to verify TCP connectivity. The connection is refused on my machine even though I can connect through the driver. And this is how it should be; otherwise there'd be a security risk.
We all like to think we learn from mistakes, whether our own or others’. So in theory, the more serious bloopers you know about, the less likely you are to be under the bright light of interrogation, explaining how you managed to screw up big-time. That’s why we put out an all-points bulletin to IT managers and vendors everywhere: For the good of humanity, tell us about the gotchas that have gotten you, so others can avoid them.
If you've ever diagnosed a bug in a web application, you've undoubtedly experienced annoyance digging through a list of fifteen exception stack traces trying to identify the one you're interested in (if it's even present), or a sinking feeling when you tailed the web server log only to find:
java.lang.NullPointerException
Thread 类
Thread 类是一个具体的类,即不是抽象类,该类封装了线程的行为。要创建一个线程,程序员必须创建一个从 Thread 类导出的新类。程序员必须覆盖 Thread 的 run() 函数来完成有用的工作。用户并不直接调用此函数;而是必须调用 Thread 的 start() 函数,该函数再调用 run()。下面的代码说明了它的用法:
创建两个新线程
import java.util.*;
class TimePrinter extends Thread {
int pauseTime;
String name;
public TimePrinter(int x, String n) {
pauseTime = x;
name = n;
}
public void run() {
while(true) {
try {
System.out.println(name + ":" + new Date(System.currentTimeMillis()));
Thread.sleep(pauseTime);
} catch(Exception e) {
System.out.println(e);
}
}
}
static public void main(String args[]) {
TimePrinter tp1 = new TimePrinter(1000, "Fast Guy");
tp1.start();
TimePrinter tp2 = new TimePrinter(3000, "Slow Guy");
tp2.start();
}
}
在本例中,我们可以看到一个简单的程序,它按两个不同的时间间隔(1 秒和 3 秒)在屏幕上显示当前时间。这是通过创建两个新线程来完成的,包括 main() 共三个线程。但是,因为有时要作为线程运行的类可能已经是某个类层次的一部分,所以就不能再按这种机制创建线程。虽然在同一个类中可以实现任意数量的接口,但 Java 编程语言只允许一个类有一个父类。同时,某些程序员避免从 Thread 类导出,因为它强加了类层次。对于这种情况,就要 runnable 接口。
Runnable 接口
此接口只有一个函数,run(),此函数必须由实现了此接口的类实现。但是,就运行这个类而论,其语义与前一个示例稍有不同。我们可以用 runnable 接口改写前一个示例。(不同的部分用黑体表示。)
创建两个新线程而不强加类层次
import java.util.*;
class TimePrinter implements Runnable {
int pauseTime;
String name;
public TimePrinter(int x, String n) {
pauseTime = x;
name = n;
}
public void run() {
while(true) {
try {
System.out.println(name + ":" + new Date(System.currentTimeMillis()));
Thread.sleep(pauseTime);
} catch(Exception e) {
System.out.println(e);
}
}
}
static public void main(String args[]) {
Thread t1 = new Thread(new TimePrinter(1000, "Fast Guy"));
t1.start();
Thread t2 = new Thread(new TimePrinter(3000, "Slow Guy"));
t2.start();
}
}
请注意,当使用 runnable 接口时,您不能直接创建所需类的对象并运行它;必须从 Thread 类的一个实例内部运行它。许多程序员更喜欢 runnable 接口,因为从 Thread 类继承会强加类层次。
Daemon - Daemon : Java based daemons or services
Introduction
Actualy only the UNIX like platforms are supported. The sources are located in the src/native/unix subdirectory of the project sources. For win32 platfroms the cygwin emulation layer is used. See cygwin for more informations.
In the futur APR may be used to provide more convinient platform support.
http://wrapper.tanukisoftware.org
Configurable tool which allows Java applications to be installed and controlled like native NT or Unix services.Includes fault correction software to automatically restart crashed or frozen JVMs. Critical when app is needed 24x7. Built for flexibility
to run my app:
nohup java -jar JarFile.jar </dev/null >>myLogFile 2>>myErrorFile&
SSHProxy是一个简单而且有用的Socks4 Socks5代理服务器,可以通过SHTTP Proxy 实现二级代理