Optional single application instance enforcement and multiple startup notification

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #16
    Originally posted by r035198x
    If only you had explained like this first time.
    I'm not sure about this but if you make the program a thread and give it a name and then check against that thread before running the program
    That won't work: when you click on a jar another java(w) process is started. Two
    different processes can't see each other's threads.

    Better just create a simple lock file or have the appliation try to open a socket,
    if the file already exists or if the socket is already open another instance is
    already running.

    kind regards,

    Jos

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #17
      Originally posted by JosAH
      That won't work: when you click on a jar another java(w) process is started. Two
      different processes can't see each other's threads.

      Better just create a simple lock file or have the appliation try to open a socket,
      if the file already exists or if the socket is already open another instance is
      already running.

      kind regards,

      Jos
      About this javaw process, is there a way of distinguishing between two javaw processes started by two different jar files?

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #18
        Originally posted by r035198x
        About this javaw process, is there a way of distinguishing between two javaw processes started by two different jar files?
        Dunno; using Unix or Linux I can see it in my ps or top list (ordered by age so I
        can see which one was started first) but I have no idea how to do that on Windows.

        kind regards,

        Jos

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #19
          Originally posted by JosAH
          Dunno; using Unix or Linux I can see it in my ps or top list (ordered by age so I
          can see which one was started first) but I have no idea how to do that on Windows.

          kind regards,

          Jos
          Probably some meddling with task manager ...
          The socket approach is the best way here. Or even have the program write/create a file. When another instance starts just check for/in that file.

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #20
            Originally posted by r035198x
            Probably some meddling with task manager ...
            The socket approach is the best way here. Or even have the program write/create a file. When another instance starts just check for/in that file.
            Yup, as I wrote above; I normally use the socket approach but a simple file
            (with the pid written in it) does fine too. I don't know how to check if another
            pid is still alive on Windows though.

            kind regards,

            Jos

            Comment

            Working...