Example usage for java.lang Thread dumpStack

List of usage examples for java.lang Thread dumpStack

Introduction

In this page you can find the example usage for java.lang Thread dumpStack.

Prototype

public static void dumpStack() 

Source Link

Document

Prints a stack trace of the current thread to the standard error stream.

Usage

From source file:Main.java

public static void main(String[] args) {

    Thread t = Thread.currentThread();
    t.setName("java2s.com thread");

    System.out.println("Thread = " + t);

    int count = Thread.activeCount();
    System.out.println("currently active threads = " + count);

    Thread.dumpStack();
}

From source file:Main.java

public static void main(String[] args) {
    JComboBox<String> emptyBox = new JComboBox<String>();
    emptyBox.addActionListener(new ActionListener() {
        @Override//from w  w w  .  ja  va2 s  .co m
        public void actionPerformed(ActionEvent e) {
            Thread.dumpStack();
        }
    });
    emptyBox.addItem("test");
}

From source file:MainClass.java

public static void main(String args[]) {
    Thread t = Thread.currentThread();
    t.setName("My Thread");
    t.setPriority(1);/*  w w w  .j av  a2  s.  co  m*/
    System.out.println("current thread: " + t);
    int active = Thread.activeCount();
    System.out.println("currently active threads: " + active);
    Thread all[] = new Thread[active];
    Thread.enumerate(all);
    for (int i = 0; i < active; i++) {
        System.out.println(i + ": " + all[i]);
    }
    Thread.dumpStack();
}

From source file:escada.tpc.common.clients.jmx.ClientEmulationStartup.java

public static void main(String args[]) {
    // create Options object
    Options options = new Options();
    // add clients option
    options.addOption("clients", true, "Number of clients concurrently accessing the database.");
    options.addOption("frag", true, "It shifts the clients in order to access different warehouses.");
    options.addOption("hostId", true, "Host identifier, allow to have statistics per host.");
    options.addOption("dbConnectionString", true, "Database JDBC url.");
    try {/*from   ww  w.  j a v  a2  s  .co m*/
        CommandLineParser parser = new PosixParser();
        CommandLine cmd = parser.parse(options, args);

        ClientEmulationStartup c = new ClientEmulationStartup();
        String clients = cmd.getOptionValue("clients");
        if (clients != null) {
            c.getWorkloadResources().setClients(new Integer(clients));
        }
        String frag = cmd.getOptionValue("frag");
        if (frag != null) {
            c.getWorkloadResources().setFrag(new Integer(frag));
        }
        String hostId = cmd.getOptionValue("hostId");
        if (hostId != null) {
            c.getWorkloadResources().setHostId(new Integer(hostId));
        }
        String dbConnectionString = cmd.getOptionValue("dbConnectionString");
        if (dbConnectionString != null) {
            c.getDatabaseResources().setConnectionString(dbConnectionString);
        }
        c.start(true);
    } catch (ParseException e) {
        System.err.println("Parsing failed.  Reason: " + e.getMessage());
        // automatically generate the help statement
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("ClientEmulationStartup", options);
    } catch (NumberFormatException e) {
        System.err.println("Parsing failed.  Reason: " + e.getMessage());
        // automatically generate the help statement
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("ClientEmulationStartup", options);
    } catch (Exception ex) {
        Thread.dumpStack();
        System.exit(-1);
    }
}

From source file:Main.java

public static void printCurrentThreadCallStack() {
    Thread.dumpStack();
}

From source file:net.sf.jabref.gui.util.FocusRequester.java

public FocusRequester(Component comp) {
    if (comp == null) {
        Thread.dumpStack();
    }

    this.comp = comp;

    run();
}

From source file:com.jivesoftware.os.routing.bird.endpoints.logging.metric.LoggerMetrics.java

@JsonIgnore
public Long get(final String key) {
    if (key == null || key.length() == 0) {
        Thread.dumpStack();
        return null;
    }/*from w  ww .ja v a 2s.  com*/
    String[] segments = key.split(">");
    Long got;
    if (segments.length == 1) {
        got = leafs.get(segments[0]);
        if (got != null) {
            return got;
        }
    } else {
        ServiceStatusNode node = null;
        for (int i = 0; i < segments.length - 1; i++) {
            if (node == null) {
                node = nodes.get(segments[i]);
                if (node == null) {
                    break;
                }
            } else {
                ServiceStatusNode next = node.getNode(segments[i]);
                if (next == null) {
                    break;
                }
                node = next;
            }
        }
        if (node != null) {
            got = node.getLeaf(segments[segments.length - 1]);
            if (got != null) {
                return got;
            }
        }
    }
    return 0L;

}

From source file:com.youxifan.utils.EMailAuthenticator.java

/**
 *    Constructor//from  w  w w  . j av a 2s.  c om
 *    @param username user name
 *    @param password user password
 */
public EMailAuthenticator(String username, String password) {
    m_pass = new PasswordAuthentication(username, password);
    if (username == null || username.length() == 0) {
        log.info("Username is NULL");
        Thread.dumpStack();
    }
    if (password == null || password.length() == 0) {
        log.info("Password is NULL");
        Thread.dumpStack();
    }
}

From source file:net.sf.jabref.exporter.layout.Layout.java

public Layout(Vector<StringInt> parsedEntries, String classPrefix) {
    Vector<LayoutEntry> tmpEntries = new Vector<>(parsedEntries.size());

    Vector<StringInt> blockEntries = null;
    LayoutEntry le;// ww  w . j  av  a  2 s  . c o  m
    String blockStart = null;

    for (StringInt parsedEntry : parsedEntries) {
        // TODO: Rewrite using switch
        if ((parsedEntry.i == LayoutHelper.IS_LAYOUT_TEXT) || (parsedEntry.i == LayoutHelper.IS_SIMPLE_FIELD)) {
            // Do nothing
        } else if (parsedEntry.i == LayoutHelper.IS_FIELD_START) {
            blockEntries = new Vector<>();
            blockStart = parsedEntry.s;
        } else if (parsedEntry.i == LayoutHelper.IS_FIELD_END) {
            if ((blockStart != null) && (blockEntries != null)) {
                if (blockStart.equals(parsedEntry.s)) {
                    blockEntries.add(parsedEntry);
                    le = new LayoutEntry(blockEntries, classPrefix, LayoutHelper.IS_FIELD_START);
                    tmpEntries.add(le);
                    blockEntries = null;
                } else {
                    LOGGER.debug(blockStart + '\n' + parsedEntry.s);
                    LOGGER.warn("Nested field entries are not implemented!");
                    Thread.dumpStack();
                }
            }
        } else if (parsedEntry.i == LayoutHelper.IS_GROUP_START) {
            blockEntries = new Vector<>();
            blockStart = parsedEntry.s;
        } else if (parsedEntry.i == LayoutHelper.IS_GROUP_END) {
            if ((blockStart != null) && (blockEntries != null)) {
                if (blockStart.equals(parsedEntry.s)) {
                    blockEntries.add(parsedEntry);
                    le = new LayoutEntry(blockEntries, classPrefix, LayoutHelper.IS_GROUP_START);
                    tmpEntries.add(le);
                    blockEntries = null;
                } else {
                    LOGGER.warn("Nested field entries are not implemented!");
                    Thread.dumpStack();
                }
            }
        } else if (parsedEntry.i == LayoutHelper.IS_OPTION_FIELD) {
            // Do nothing
        }

        if (blockEntries == null) {
            tmpEntries.add(new LayoutEntry(parsedEntry, classPrefix));
        } else {
            blockEntries.add(parsedEntry);
        }
    }

    layoutEntries = new LayoutEntry[tmpEntries.size()];

    for (int i = 0; i < tmpEntries.size(); i++) {
        layoutEntries[i] = tmpEntries.get(i);
        // Note if one of the entries has an invalid formatter:
        if (layoutEntries[i].isInvalidFormatter()) {
            missingFormatters.addAll(layoutEntries[i].getInvalidFormatters());
        }
    }
}

From source file:com.phicomm.account.network.NetworkConnectionImpl.java

/**
 * Call the webservice using the given parameters to construct the request and return the
 * result.// w  ww  .  j a  va2  s  .c om
 *
 * @param context The context to use for this operation. Used to generate the user agent if
 *            needed.
 * @param urlValue The webservice URL.
 * @param method The request method to use.
 * @param parameterList The parameters to add to the request.
 * @param headerMap The headers to add to the request.
 * @param isGzipEnabled Whether the request will use gzip compression if available on the
 *            server.
 * @param userAgent The user agent to set in the request. If null, a default Android one will be
 *            created.
 * @param postText The POSTDATA text to add in the request.
 * @param credentials The credentials to use for authentication.
 * @param isSslValidationEnabled Whether the request will validate the SSL certificates.
 * @return The result of the webservice call.
 */
public static ConnectionResult execute(Context context, String urlValue, Method method,
        ArrayList<BasicNameValuePair> parameterList, HashMap<String, String> headerMap, boolean isGzipEnabled,
        String userAgent, String postText, UsernamePasswordCredentials credentials,
        boolean isSslValidationEnabled) throws ConnectionException {
    Thread.dumpStack();
    Log.i("ss", "NetworkConnectionImpl_____________________________________execute__urlValue:" + urlValue);
    HttpURLConnection connection = null;
    try {
        // Prepare the request information
        if (userAgent == null) {
            userAgent = UserAgentUtils.get(context);
        }
        if (headerMap == null) {
            headerMap = new HashMap<String, String>();
        }
        headerMap.put(HTTP.USER_AGENT, userAgent);
        if (isGzipEnabled) {
            headerMap.put(ACCEPT_ENCODING_HEADER, "gzip");
        }
        headerMap.put(ACCEPT_CHARSET_HEADER, UTF8_CHARSET);
        if (credentials != null) {
            headerMap.put(AUTHORIZATION_HEADER, createAuthenticationHeader(credentials));
        }

        StringBuilder paramBuilder = new StringBuilder();
        if (parameterList != null && !parameterList.isEmpty()) {
            for (int i = 0, size = parameterList.size(); i < size; i++) {
                BasicNameValuePair parameter = parameterList.get(i);
                String name = parameter.getName();
                String value = parameter.getValue();
                if (TextUtils.isEmpty(name)) {
                    // Empty parameter name. Check the next one.
                    continue;
                }
                if (value == null) {
                    value = "";
                }
                paramBuilder.append(URLEncoder.encode(name, UTF8_CHARSET));
                paramBuilder.append("=");
                paramBuilder.append(URLEncoder.encode(value, UTF8_CHARSET));
                paramBuilder.append("&");
            }
        }

        // Log the request
        if (true) {
            Log.d(TAG, "Request url: " + urlValue);
            Log.d(TAG, "Method: " + method.toString());

            if (parameterList != null && !parameterList.isEmpty()) {
                Log.d(TAG, "Parameters:");
                for (int i = 0, size = parameterList.size(); i < size; i++) {
                    BasicNameValuePair parameter = parameterList.get(i);
                    String message = "- \"" + parameter.getName() + "\" = \"" + parameter.getValue() + "\"";
                    Log.d(TAG, message);
                }

                Log.d(TAG, "Parameters String: \"" + paramBuilder.toString() + "\"");
            }

            if (postText != null) {
                Log.d(TAG, "Post data: " + postText);
            }

            if (headerMap != null && !headerMap.isEmpty()) {
                Log.d(TAG, "Headers:");
                for (Entry<String, String> header : headerMap.entrySet()) {
                    Log.d(TAG, "- " + header.getKey() + " = " + header.getValue());
                }
            }
        }

        // Create the connection object
        URL url = null;
        String outputText = null;
        switch (method) {
        case GET:
        case DELETE:
            String fullUrlValue = urlValue;
            if (paramBuilder.length() > 0) {
                fullUrlValue += "?" + paramBuilder.toString();
            }
            url = new URL(fullUrlValue);
            connection = HttpUrlConnectionHelper.openUrlConnection(url);
            break;
        case PUT:
        case POST:
            url = new URL(urlValue);
            connection = HttpUrlConnectionHelper.openUrlConnection(url);
            connection.setDoOutput(true);

            if (paramBuilder.length() > 0) {
                outputText = paramBuilder.toString();
                headerMap.put(HTTP.CONTENT_TYPE, "application/x-www-form-urlencoded");
                headerMap.put(HTTP.CONTENT_LEN, String.valueOf(outputText.getBytes().length));
            } else if (postText != null) {
                outputText = postText;
            }
            break;
        }

        // Set the request method
        connection.setRequestMethod(method.toString());

        // If it's an HTTPS request and the SSL Validation is disabled
        if (url.getProtocol().equals("https") && !isSslValidationEnabled) {
            HttpsURLConnection httpsConnection = (HttpsURLConnection) connection;
            httpsConnection.setSSLSocketFactory(getAllHostsValidSocketFactory());
            httpsConnection.setHostnameVerifier(getAllHostsValidVerifier());
        }

        // Add the headers
        if (!headerMap.isEmpty()) {
            for (Entry<String, String> header : headerMap.entrySet()) {
                connection.addRequestProperty(header.getKey(), header.getValue());
            }
        }

        // Set the connection and read timeout
        connection.setConnectTimeout(OPERATION_TIMEOUT);
        connection.setReadTimeout(OPERATION_TIMEOUT);

        // Set the outputStream content for POST and PUT requests
        if ((method == Method.POST || method == Method.PUT) && outputText != null) {
            OutputStream output = null;
            try {
                output = connection.getOutputStream();
                output.write(outputText.getBytes());
            } finally {
                if (output != null) {
                    try {
                        output.close();
                    } catch (IOException e) {
                        // Already catching the first IOException so nothing to do here.
                    }
                }
            }
        }

        String contentEncoding = connection.getHeaderField(HTTP.CONTENT_ENCODING);

        int responseCode = connection.getResponseCode();
        boolean isGzip = contentEncoding != null && contentEncoding.equalsIgnoreCase("gzip");
        Log.d(TAG, "Response code: " + responseCode);

        if (responseCode == HttpStatus.SC_MOVED_PERMANENTLY) {
            String redirectionUrl = connection.getHeaderField(LOCATION_HEADER);
            throw new ConnectionException("New location : " + redirectionUrl, redirectionUrl);
        }

        InputStream errorStream = connection.getErrorStream();
        if (errorStream != null) {
            String error = convertStreamToString(errorStream, isGzip);
            throw new ConnectionException(error, responseCode);
        }

        String body = convertStreamToString(connection.getInputStream(), isGzip);

        if (true) {
            Log.v(TAG, "Response body: ");

            int pos = 0;
            int bodyLength = body.length();
            while (pos < bodyLength) {
                Log.v(TAG, body.substring(pos, Math.min(bodyLength - 1, pos + 200)));
                pos = pos + 200;
            }
        }

        return new ConnectionResult(connection.getHeaderFields(), body);
    } catch (IOException e) {
        Log.e(TAG, "IOException", e);
        throw new ConnectionException(e);
    } catch (KeyManagementException e) {
        Log.e(TAG, "KeyManagementException", e);
        throw new ConnectionException(e);
    } catch (NoSuchAlgorithmException e) {
        Log.e(TAG, "NoSuchAlgorithmException", e);
        throw new ConnectionException(e);
    } finally {
        if (connection != null) {
            connection.disconnect();
        }
    }
}