Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8181037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:23:18+00:00 2026-06-07T00:23:18+00:00

I am developing eclipse plugin for our organization . We are opening multiple servers[minimum

  • 0

I am developing eclipse plugin for our organization . We are opening multiple servers[minimum 10 servers] on a user machine using this plugin via eclipse . For starting servers we want port numbers which has been not already binded . For that , I am using serversocket to check this . I think it’s a costly operation to open a serversocket object . Internally serversocket will check the port is already binded or not It takes minimum 50 milliseconds . Here is my code to return a free port . Is there any way to find already occupied ports without using OS Commands and opening ServerSocket ?

     /**
     *Tries 100 times
     * @param port
     * modes
     *  1.increment - 1
     *  This mode increment the port with your start value . But it's costly operation because each time we open a socket and check the port is free .
     *  2.decrement - 2
     *  Invert of increment.
     *  3.random - 3
     *  Randomly choose based on your starting point
     * @return
     */
    public static String getDefaultPort(int port , int mode){
        int retry = 100;
        int random = 3;
        int increment = 1;
        int decrement = 2;
        while(true){
            //this is for preventing stack overflow error.
            if(retry < 1){ //retries 100 times .
                break;
            }
            if(mode==increment){
                port++;
            }else if(mode == decrement){
                port--;
            }else if(mode == random){
                port = (int) (port+Math.floor((Math.random()*1000)));
            }
            if(validate(port+"")){
                long end = System.currentTimeMillis();
                return port+"";
            }
        }
        return "";
    }

    public boolean validate(String input) {
    boolean status = true;
    try {
        int port = Integer.parseInt(input);
        ServerSocket ss = new ServerSocket(port);
        ss.close();         
    }
    catch (Exception e) {
        status = false;
    }
    return status;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:23:21+00:00Added an answer on June 7, 2026 at 12:23 am

    The quickest way would be to run native netstat command and parse the output. It’s available on Windows as well and Linux platform. A typical netstat command output is as follows

     Proto  Local Address          Foreign Address        State
     TCP    MYHOST:8080           MYHOST.mydomain.co.in:0  LISTENING
     TCP    MYHOST:9090           MYHOST.mydomain.co.in:0  LISTENING
     TCP    MYHOST:3389           MYHOST.mydomain.co.in:0  LISTENING
     TCP    MYHOST:7717           MYHOST.mydomain.co.in:0  LISTENING
     TCP    MYHOST:51114          MYHOST.mydomain.co.in:0  LISTENING
     TCP    MYHOST:netbios-ssn    MYHOST.mydomain.co.in:0  LISTENING
     TCP    MYHOST:netbios-ssn    MYHOST.mydomain.co.in:0  LISTENING
     TCP    MYHOST:2573           hj-lyncfe.mydomain.co.in:5061  ESTABLISHED
     TCP    MYHOST:2591           mail.mydomain.co.in:8502  ESTABLISHED
     TCP    MYHOST:2593           mail.mydomain.co.in:8502  ESTABLISHED
    

    The ports of your interest are in the column Local Address with State in LISTENING

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am developing a eclipse plugin . In this plugin i am using reflection
I am developing a plugin for eclipse. In this plugin I need to be
I'm developing a plugin for Eclipse. I'd like it to suggest the user to
I'm developing Scala code using Eclipse, often when I run tests I get this
I'm developing an application using the Blackberry plugin for eclipse and I am getting
I am developing an app using Eclipse Plugin with BlackBerry JRE 4.5 to support
I'm developing a Eclipse plugin. From this plugin I want to instantiate classes from
I'm developing an eclipse plugin and I'm starting to have performance problems, so I's
I'm developing an Eclipse Plugin with support for my DSL using the Xtext framework.
I am developing an Eclipse Plugin for working with Java source files. When the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.