How to synchronize apps running?

M

masterwally

Hello,

I have a following issue: I have a application, that binds the two
other programs together in a way, that it runs them one after the
other. The issue is, that the first one is an application that opens a
number of sockets and waits for the incoming connections. The second
application connects to those sockets, transmits something and closes.
The thing is, that the first application is a Java app, while the
second one is native. And, before the first application is able to
start and open sockets, the second one runs, tries to connect, fails
and exits. I don't have any influence on that, I can only modify
sources of the first application and the "master" one. Do you have
some ideas on a nice way how master application can delay execution of
the second program? I must only say, that "sleep" is insufficient, as
I need to make it as fast as possible, so waiting for, let's say, 5
seconds and then commencing execution of the native application is out
of the question. Any ideas? Thanks in advance!
 
G

Gordon Beaton

And, before the first application is able to start and open sockets,
the second one runs, tries to connect, fails and exits. I don't have
any influence on that, I can only modify sources of the first
application and the "master" one. Do you have some ideas on a nice
way how master application can delay execution of the second
program?

Your "master" application can start app1, then make several attempts
to connect to the socket. When that succeeds, it can close the
connection and start app2, which should then also succeed. This
assumes that app1 correctly deals with closed connections and multiple
clients.

/gordon

--
 
M

masterwally

Your "master" application can start app1, then make several attempts
to connect to the socket. When that succeeds, it can close the
connection and start app2, which should then also succeed. This
assumes that app1 correctly deals with closed connections and multiple
clients.

/gordon

--

One thing I forgot to mention: the first app waits for only one
connection, and - after the socket closes - terminates itself. So your
solution would close my app1 after "master" tries succeeds...
 
G

Gordon Beaton

One thing I forgot to mention: the first app waits for only one
connection, and - after the socket closes - terminates itself. So
your solution would close my app1 after "master" tries succeeds...

So change it. You said you could modify app1 and the master app.

You might also parse the output of an external tool like "lsof" or
"netstat" (or whatever's available for your platform) to see when the
socket is waiting for connections.

/gordon

--
 
G

Gordon Beaton

One thing I forgot to mention: the first app waits for only one
connection, and - after the socket closes - terminates itself. So
your solution would close my app1 after "master" tries succeeds...

Another suggestion: master starts app1, then creates own ServerSocket
before starting app2. App2 connects to master's server, master then
connects to app1 (retrying if necessary) then acts as proxy between
the two applications.

/gordon

--
 
L

Laurent D.A.M. MENTEN

(e-mail address removed) a écrit :
Hello,

I have a following issue: I have a application, that binds the two
other programs together in a way, that it runs them one after the
other. The issue is, that the first one is an application that opens a
number of sockets and waits for the incoming connections. The second
application connects to those sockets, transmits something and closes.
The thing is, that the first application is a Java app, while the
second one is native. And, before the first application is able to
start and open sockets, the second one runs, tries to connect, fails
and exits. I don't have any influence on that, I can only modify
sources of the first application and the "master" one. Do you have
some ideas on a nice way how master application can delay execution of
the second program? I must only say, that "sleep" is insufficient, as
I need to make it as fast as possible, so waiting for, let's say, 5
seconds and then commencing execution of the native application is out
of the question. Any ideas? Thanks in advance!

you may also wrap the second application and wait for your conditions to
be met before starting the real application...
 

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,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top