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 247371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:15:13+00:00 2026-05-11T21:15:13+00:00

I need to prevent users from starting my Java application (WebStart Swing app) multiple

  • 0

I need to prevent users from starting my Java application (WebStart Swing app) multiple times. So if the application is already running it shouldn’t be possible to start it again or show a warning / be closed again.

Is there some convenient way to achieve this? I thought about blocking a port or write sth to a file. But hopefully you can access some system properties or the JVM?

btw. target platform is Windows XP with Java 1.5

  • 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-05-11T21:15:13+00:00Added an answer on May 11, 2026 at 9:15 pm

    I think your suggestion of opening a port to listen when you start your application is the best idea.

    It’s very easy to do and you don’t need to worry about cleaning it up when you close your application. For example, if you write to a file but someone then kills the processes using Task Manager the file won’t get deleted.

    Also, if I remember correctly there is no easy way of getting the PID of a Java process from inside the JVM so don’t try and formulate a solution using PIDs.

    Something like this should do the trick:

    private static final int PORT = 9999;
    private static ServerSocket socket;    
    
    private static void checkIfRunning() {
      try {
        //Bind to localhost adapter with a zero connection queue 
        socket = new ServerSocket(PORT,0,InetAddress.getByAddress(new byte[] {127,0,0,1}));
      }
      catch (BindException e) {
        System.err.println("Already running.");
        System.exit(1);
      }
      catch (IOException e) {
        System.err.println("Unexpected error.");
        e.printStackTrace();
        System.exit(2);
      }
    }
    

    This sample code explicitly binds to 127.0.0.1 which should avoid any firewall warnings, as any traffic on this address must be from the local system.

    When picking a port try to avoid one mentioned in the list of Well Known Ports. You should ideally make the port used configurable in a file or via a command line switch in case of conflicts.

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

Sidebar

Ask A Question

Stats

  • Questions 211k
  • Answers 211k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer just try this code while(st.hasMoreTokens()) { if(count==1) { e.ename=st.nextToken(); count++;… May 12, 2026 at 10:12 pm
  • Editorial Team
    Editorial Team added an answer Just do a diff between your branch and upstream. git… May 12, 2026 at 10:12 pm
  • Editorial Team
    Editorial Team added an answer Change the model type of SoupList to a type which… May 12, 2026 at 10:12 pm

Related Questions

Having used some PHP frameworks such as Codeigniter and Kohana for some smaller sites,
I am not sure about the exact purpose of the following Rampion's code .
I think I need some clarifications regarding WPFs Dispatcher.Invoke and Dispatcher.BeginInvoke usage. Suppose I
I've got a problem here with an MSI deployment that I'm working on (using

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.