Pausing a java program and then having a different program start it up

I was wondering if there was a way to tell my Java program to stop and wait until the operating system or another program tells is to continue, and then the question is how would a different program (let's say it's a different Java) program would make it move? Is that possible?

The issue in more detail is this: I have a java program-A that runs and outputs a file1, another program-B then uses file1 runs and outputs file2 and I want the first program-A to take that file2 and do some work on it and so forth... but I have no way for program-A to know if program-B is done. Thus I want program-A to go to sleep until program-B writes the file and nudges program-A. Program-B doesn't have to be a Java program, it might be C, perl, or even matlab.

If this isn't possible is there a way that is?

[818 byte] By [mikebasa] at [2007-11-27 10:17:57]
# 1

Probably the easiest way is to use sockets. Your java app. listens on a socket until this external system connects to it and pumps a particular message down it, upon which it starts again

georgemca at 2007-7-28 15:54:41 > top of Java-index,Java Essentials,Java Programming...
# 2

It is absolutely possible. The most professional way to do it would be to do it all with web services based on XML schemas (.xsd files)

Program A does something, makes a web call to Program B, then Program B calls back program A when it's done

tjacobs01a at 2007-7-28 15:54:41 > top of Java-index,Java Essentials,Java Programming...
# 3

what I'm really interested for is a version of what is done in C:

pause()--Suspend Process Until Signal Received

mikebasa at 2007-7-28 15:54:41 > top of Java-index,Java Essentials,Java Programming...
# 4

As georgemc says, sockets are also a good way to go. The advantage is that it's normally less coding /easier to do for a simple app

tjacobs01a at 2007-7-28 15:54:41 > top of Java-index,Java Essentials,Java Programming...
# 5

> what I'm really interested for is a version of what

> is done in C:

> pause()--Suspend Process Until Signal Received

You can do this by listening on some update event - either a file system update or incoming data on a socket or so.

tjacobs01a at 2007-7-28 15:54:41 > top of Java-index,Java Essentials,Java Programming...
# 6

tjacobs can you elaborate on that last point or point me to a tutorial/howto/guide/class name

Thank you.

mikebasa at 2007-7-28 15:54:41 > top of Java-index,Java Essentials,Java Programming...
# 7

1. If the other process is willing to use them too, you could try file locks.

2. Program B could write to a temp file, then rename it to the proper name

when done writing. Program A could then just poll for the appearance of the file.

BigDaddyLoveHandlesa at 2007-7-28 15:54:41 > top of Java-index,Java Essentials,Java Programming...
# 8

how would it poll for the appearance of the file? just keep checking if it exists?

mikebasa at 2007-7-28 15:54:41 > top of Java-index,Java Essentials,Java Programming...
# 9

> how would it poll for the appearance of the file?

> just keep checking if it exists?

Yes, I mean sleeping then checking, and doing that in a loop. Nothing fancy, but it works.

BigDaddyLoveHandlesa at 2007-7-28 15:54:41 > top of Java-index,Java Essentials,Java Programming...
# 10

Also a note this is all being done on Windows. So is there some windows command that can be executed that will stop the process and wait for osmething to resume it?

mikebasa at 2007-7-28 15:54:41 > top of Java-index,Java Essentials,Java Programming...
# 11

> Also a note this is all being done on Windows. So is

> there some windows command that can be executed that

> will stop the process and wait for osmething to

> resume it?

You can manage that in your code the way BDLH's mentioned. The program waiting on the new file would sleep/pause or run an infinite loop until it finds the file with the name it is expecting. It will essentially be paused and will resume when it finds the file name.

_helloWorld_a at 2007-7-28 15:54:41 > top of Java-index,Java Essentials,Java Programming...
# 12

The problem with having the program wait for a file is that there is actually a 3rd program in between (I oversimplified in the original post) and it needs to process the file before telling the 3rd program to move along so I guess all programs could be sitting around waiting for that file but will that add a lot of overhead (constantly seeking on the harddrive?)

mikebasa at 2007-7-28 15:54:41 > top of Java-index,Java Essentials,Java Programming...