Compare java instances

R

Robina Brintha

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
 
R

Rogan Dawes

Robina said:
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
 
A

Andrew Thompson

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)
 
R

Robina Brintha

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?
 
O

Oliver Wong

Robina Brintha said:
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
 
O

Oliver Wong

Robina Brintha said:
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
 
A

Andrew Thompson

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top