यह है कि मैं जेट्टी के लिए तैनात किए गए सर्वलेट का कोड है:जेट्टी सर्वलेट है कि ग्राहक पता नहीं लगा पाया डिस्कनेक्ट कर दिया गया
public class StreamServlet extends HttpServlet
{
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/xml; charset=UTF-8");
response.setCharacterEncoding("UTF-8");
InputStream is = this.getServletContext().getResourceAsStream("A.xml");
BufferedReader reader = new BufferedReader(
new InputStreamReader(is, Charset.forName("UTF-8")));
String line = "";
try
{
while((line = reader.readLine()) != null) {
getServletContext().log(line);
writer.println(line);
writer.flush();
Thread.sleep(1500); // for testing
}
}
catch (InterruptedException e)
{
getServletContext().log("exception",e);
}
}
}
मैं तो कमांड लाइन
curl -i http://localhost:8080/foo/servlet
फ़ाइल A.xml
शामिल पर भाग गया लगभग 13,000 लाइनें; इसलिए कर्ल 1.5 सेकंड के बाद प्राप्त प्रत्येक पंक्ति को सही तरीके से प्रदर्शित करता है। मैंने फिर कर्ल में बाधा डाली, लेकिन मेरे आश्चर्य के लिए सर्वलेट चलने पर जारी रहा; i.e इस दौरान लूप।
while((line = reader.readLine()) != null) {
getServletContext().log(line);
writer.println(line);
writer.flush();
Thread.sleep(1500); // for testing
}
यह इस व्यवहार को क्यों प्रदर्शित करता है? मैं निरंतरता का उपयोग नहीं कर रहा हूँ। मैं जेटी 6.1.26 चला रहा हूँ। मैं क्या चाहता हूं: सर्वलेट थ्रेड को रोकना चाहिए जब यह पता लगाता है कि क्लाइंट ने http कनेक्शन को समाप्त कर दिया है।