Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Intercept instance of the program already running

  1. #1
    Junior Member
    Join Date
    Oct 2019
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Intercept instance of the program already running

    Hello to everyone,

    I am not sure if this is the right place for this type of question ...

    I would like to create a program that before displaying the graphical interface, checks if there is already an instance of the same program in execution and if it exists, pass the focus to that instance (in practice, bring it to the front compared to other applications) and terms its execution.

    This is because this program, after executing any operation requested by the user, should make itself invisible while remaining in execution, so that at a subsequent run of the same application the invisible instance is simply activated with the aforementioned method.

    I realized a similar application when I developed in VB6 obviously only on Windows up to XP.

    The application should be totally cross-platform, because I use WinXP, Win7, Win8.1, Kubuntu 14.04, Kubuntu 18.04.

    Now I'm using Netbeans (both on Windows and on Kubuntu) as a development tool.

    I don't know if I explained myself.

    The aim is to speed up the appearance of the program whenever I need it, because the first activation is too slow.

    Can anyone give me directions on how to do this?

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Intercept instance of the program already running

    The only way I know for a java program to detect that another instance of the java program is running is by using a server socket. The first instance of the program grabs the port with a server socket. When the next instance of the program tries to get the port it will get an error - already in use.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Oct 2019
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Intercept instance of the program already running

    OK thanks.
    I'll have to study how to use sockets.

    Now the problem is, how to communicate to the previous executing instance to bring it to the fore.
    do you have any indication?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Intercept instance of the program already running

    Again sockets could be used by one program to communicate with another. If the first program has opened a server socket, the second program could connect to that socket to pass info.
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    ZioCrick (October 30th, 2019)

  6. #5
    Junior Member
    Join Date
    Oct 2019
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Intercept instance of the program already running

    Ok Norm.
    Thanks a lot.
    So, now I have to study a lot.

Similar Threads

  1. need Help to get this program running
    By adam1991 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: October 4th, 2014, 11:32 PM
  2. Running my Java first program
    By gauthamtin15 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 5th, 2014, 07:02 AM
  3. Replies: 21
    Last Post: June 12th, 2013, 11:33 AM
  4. Need to write a public instance method for a simple dice program
    By akira25 in forum Object Oriented Programming
    Replies: 3
    Last Post: April 9th, 2012, 04:46 AM
  5. Entering and running a Program
    By Bijaysadhok in forum Java Theory & Questions
    Replies: 1
    Last Post: February 23rd, 2012, 07:15 AM