Compare java instances

Discussion in 'Java' started by Robina Brintha, Apr 10, 2007.

  1. Hi all,

    I am quite new to Java.

    I have an issue to be solved. I want to compare two JVM instances. Let
    me go in detail I am instantiating two or more java instances of
    particular application and I wanted to know which java instance
    started first. For that I am generating random numbers in the
    constructor of the class and trying to store it in a static variable
    and comparing this with newly generated randon number. But then it
    didnt work.

    Is there any other easy solution to do that?

    Can anyone give some hint?

    Thanks in advance

    regards,
    robina
     
    Robina Brintha, Apr 10, 2007
    #1
    1. Advertising

  2. Robina Brintha

    Rogan Dawes Guest

    Robina Brintha wrote:
    > Hi all,
    >
    > I am quite new to Java.
    >
    > I have an issue to be solved. I want to compare two JVM instances. Let
    > me go in detail I am instantiating two or more java instances of
    > particular application and I wanted to know which java instance
    > started first. For that I am generating random numbers in the
    > constructor of the class and trying to store it in a static variable
    > and comparing this with newly generated randon number. But then it
    > didnt work.
    >
    > Is there any other easy solution to do that?
    >
    > Can anyone give some hint?
    >
    > Thanks in advance
    >
    > regards,
    > robina
    >


    How about storing System.currentTimeMillis()?

    http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html#currentTimeMillis()

    I have no idea how you are comparing these numbers, though. Over the
    network? Also keep in mind that if you are in different time zones, you
    need to account for that.

    Rogan
     
    Rogan Dawes, Apr 10, 2007
    #2
    1. Advertising

  3. Robina Brintha wrote:
    ..
    >I have an issue to be solved.


    What is the issue to be solved?
    What ability are you attempting to offer to the end user?
    (I trimmed the rest, because you seemed to be
    describing a strategy you thought might achieve
    the goal, without actually stating what the goal was)

    --
    Andrew Thompson
    http://www.athompson.info/andrew/

    Message posted via http://www.javakb.com
     
    Andrew Thompson, Apr 10, 2007
    #3
  4. Dear Andrew,

    I have an aplication which will be run by different clients at a time.
    Each instance will first find if an update is needed through a method
    in the application. The instance which finds that first will be the
    coordinator who sends message(multicast) to all other instances.

    So in this scenario if two instances finds that an update is needed in
    exactly the same time they have to compete using some strategy and
    agree upon that either one of them who wins the strategy will be the
    coordinator who will send update message to all the others in the
    group. Its the issue of what strategy can I use to choose coordinator
    and how to share that state among other instances? Hope I have
    explained bit clear now. Do you have any idea?
     
    Robina Brintha, Apr 10, 2007
    #4
  5. Robina Brintha

    Oliver Wong Guest

    "Robina Brintha" <> wrote in message
    news:...
    > Dear Andrew,
    >
    > I have an aplication which will be run by different clients at a time.
    > Each instance will first find if an update is needed through a method
    > in the application. The instance which finds that first will be the
    > coordinator who sends message(multicast) to all other instances.
    >
    > So in this scenario if two instances finds that an update is needed in
    > exactly the same time they have to compete using some strategy and
    > agree upon that either one of them who wins the strategy will be the
    > coordinator who will send update message to all the others in the
    > group. Its the issue of what strategy can I use to choose coordinator
    > and how to share that state among other instances? Hope I have
    > explained bit clear now. Do you have any idea?


    Will the instances be running on the same computer, the same LAN, or
    over the internet?

    - Oliver
     
    Oliver Wong, Apr 10, 2007
    #5
  6. On Apr 10, 5:27 pm, "Oliver Wong" <> wrote:
    > "Robina Brintha" <> wrote in message
    >
    > news:...
    >
    > > Dear Andrew,

    >
    > > I have an aplication which will be run by different clients at a time.
    > > Each instance will first find if an update is needed through a method
    > > in the application. The instance which finds that first will be the
    > > coordinator who sends message(multicast) to all other instances.

    >
    > > So in this scenario if two instances finds that an update is needed in
    > > exactly the same time they have to compete using some strategy and
    > > agree upon that either one of them who wins the strategy will be the
    > > coordinator who will send update message to all the others in the
    > > group. Its the issue of what strategy can I use to choose coordinator
    > > and how to share that state among other instances? Hope I have
    > > explained bit clear now. Do you have any idea?

    >
    > Will the instances be running on the same computer, the same LAN, or
    > over the internet?
    >
    > - Oliver


    instances run in same computer...
     
    Robina Brintha, Apr 10, 2007
    #6
  7. Robina Brintha

    Oliver Wong Guest

    "Robina Brintha" <> wrote in message
    news:...
    > On Apr 10, 5:27 pm, "Oliver Wong" <> wrote:
    >> "Robina Brintha" <> wrote in message
    >>
    >> news:...
    >>
    >> > I have an aplication which will be run by different clients at a
    >> > time.
    >> > Each instance will first find if an update is needed through a method
    >> > in the application. The instance which finds that first will be the
    >> > coordinator who sends message(multicast) to all other instances.

    >>

    [...]
    >> Will the instances be running on the same computer, the same LAN,
    >> or
    >> over the internet?
    >>

    >
    > instances run in same computer...


    Simplest solution is to try to acquire an exclusive resource in an
    atomic fashion, and the first process to have successfully required this
    resource is the "first" instance, and can act as the server or coordinator
    or whatever.

    Example include listening on a specific port or trying to gain
    exclusive write-access to a specific file.

    - Oliver
     
    Oliver Wong, Apr 10, 2007
    #7
  8. Robina Brintha wrote:
    ...
    >I have an aplication which will be run by different clients at a time.


    You mention later that this will all be happening on one
    single PC. *

    >Each instance will first find if an update is needed through a method
    >in the application. The instance which finds that first will be the
    >coordinator who sends message(multicast) to all other instances.


    * If that is the case, you might use the JNLP based SingleInstanceService **
    to open a 'controller' application that launches a single screen of the
    'user visible area' (AKA 'the application'). Later invocations will
    'report to' that first controller instance, so it is possible to open
    other UVA's as needed, while the controller is overseeing updates for
    all.

    ** Here is an example <http://www.physci.org/jws/#sis>

    --
    Andrew Thompson
    http://www.athompson.info/andrew/

    Message posted via JavaKB.com
    http://www.javakb.com/Uwe/Forums.aspx/java-general/200704/1
     
    Andrew Thompson, Apr 11, 2007
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Wohlbier
    Replies:
    2
    Views:
    397
    Josiah Carlson
    Feb 22, 2004
  2. Replies:
    2
    Views:
    302
  3. droodle
    Replies:
    2
    Views:
    382
  4. Replies:
    8
    Views:
    488
    James Stroud
    Jan 29, 2009
  5. Greg Hauptmann
    Replies:
    7
    Views:
    158
    Greg Hauptmann
    Sep 5, 2009
Loading...

Share This Page