users@glassfish.java.net

Re: socket connection timeout in SJSAS

From: <glassfish_at_javadesktop.org>
Date: Mon, 05 Mar 2007 02:45:57 PST

MY OS

Linux Ubuntu 6.10

------

MY ENV

Java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

------

IMPORTANT!

With com.sun.enterprise.server.ss.ASQuickStartup=false in jvm options the CONNECTION TIMEOUT WORKS PROPERLY.

------

THE SAMPLE CODE

/*
 * SocketServlet.java
 *
 */

package com.mydomain.servlets;

import java.io.*;
import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;

/**
 *
 * @author ---
 * @version
 */
public class SocketServlet extends HttpServlet {
    
    /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String domain = request.getParameter("domain");
        int port = Integer.parseInt(request.getParameter("port"));
        try {
            connect(domain, port); // *** HERE THE CODE HAS PROBLEMS; NO TIMEOUT
            out.println("Ok. I'm connected.");
        } catch (Throwable ex) {
            // ex.printStackTrace();
            out.println(ex.getMessage());
        }
        out.close();
    }
    
    /** Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
    
    /** Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
    
    /** Returns a short description of the servlet.
     */
    public String getServletInfo() {
        return "Short description";
    }
    
    // Connect
    private void connect(String domainName, int port) throws Throwable {
        Socket socket = null;
        // inet remote address
        InetAddress inetRemoteAddress = InetAddress.getByName(domainName);
        // unbound socket
        socket = new Socket();
        // socket adrress
        InetSocketAddress remoteSocketAddress = new InetSocketAddress(inetRemoteAddress, port);
        // connect (CTO = 2000 ms)
        socket.connect(remoteSocketAddress, 2000);
    }
}

------
QUESTIONS

Is this option a sort of workaround?

<jvm-options>com.sun.enterprise.server.ss.ASQuickStartup=false</jvm-options>

Many thanks and regards!

Emilio
[Message sent by forum member 'emilioremogna' (emilioremogna)]

http://forums.java.net/jive/thread.jspa?messageID=206176