Windows 응용 프로그램 서버에 설치된 Tomcat 6에서 실행되는 웹 응용 프로그램이 있습니다.이 응용 프로그램은 다른 서버와 소켓 연결을 열어 일부 데이터를 검색합니다. 이 응용 프로그램은 몇 달 동안 사용되었습니다. 그러나 두 가지 경우에 웹 응용 프로그램이 작동하지 않는 이유가 있습니다. netstat 명령 (-ano 사용)을 실행하는 두 가지 경우에서 웹 응용 프로그램이 소켓 연결을 통해 연결하는 포트에서 약 4.000 개의 tcp 연결 (TIME_WAIT 상태)을 보였습니다.웹 응용 프로그램을 통해 시작된 Java 소켓 연결이 서버가 다시 시작될 때 다시 열림
이상한 점은 여기에서 시작됩니다. 잠시 후에 바람둥이를 멈추고 잠시 후 (netstat를 다시 실행) 그다지 멈추지 않습니다. 나는 tomcat을 다시 시작하고이 연결은 모두 TIME_WAIT 상태로 되돌아갑니다 !!!
이러한 연결이 다시 열리는 이유를 알 수 없습니다. 내가 빠진 것이 분명 할 수도 있습니다. 어떤 아이디어?
감사합니다.
는 편집 : writeReadSocket이
public void openSocketConnection() throws Exception {
socket = createSingleSocket();
socket.setSoTimeout(5000);
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF8")), true);
in = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF8"));
}
/**
* Closes socket and output input streams.
*/
public void closeSocketConnection() throws IOException {
socket.close();
out.close();
in.close();
}
/**
* Writes the input to the socket and returns the output response
*
* @param input
* a String to write on the socket
* @return output a String that the socket returns
* @throws Exception
*/
public String writeReadSocket(String input) throws Exception {
openSocketConnection();
out.println(input);
logger.debug("Socket Input:" + input);
String output = in.readLine();
logger.debug("Socket output:" + output);
closeSocketConnection();
return output;
}
/**
* Method overiden by Spring. We use the method injection technique, so that we have a new socket instance in every call to openSocketConnection()
* method
*/
public abstract Socket createSingleSocket();
호출되는 방법 :
여기소켓 관리를 수행하는 코드입니다.
마지막 메서드 (createSingleSocket)는 봄에 사용되므로 openConnection() 메서드를 호출 할 때마다 새 Socket 인스턴스를 가질 수 있습니다. (그런데 새로운 소켓이 필요한지 확실하지 않습니다. 모든 요청). 사물의
이<!-- prototype scope is used to instantiate a new socket instance in every createSingleSocket() method call. -->
<bean id="socket" class="java.net.Socket" scope="prototype">
<constructor-arg type="String" value="${socket.url}"/>
<constructor-arg type="int" value="${socket.port}"/>
</bean>
<bean id="socketConnector" class="gr.diassa.dsjsonrpcsuite.socket.SocketConnector">
<lookup-method name="createSingleSocket" bean="socket"/>
</bean>
사용중인 클라이언트 소켓 관련 코드를 게시 할 수 있습니까? – Santosh