It is a little high level question and I'm looking for possible solutions.
So I've a Java program A and another Java program B. They are supposed to run in a VM. Now there is one constraint - that B shouldn't run until a file, say C.xml
, is generated by A and a few minutes after. How can I solve this problem ?
One solution might be using some scheduler which schedules A and then runs B based of a trigger (I've no idea which scheduler can be used).
And another is write a service that runs on the VM and waits for C.xml
to be generated. Once its generated, kicks-off B.
Any other ideas ? (or any help/comment on the two ideas that I've suggested).
Asked
Active
Viewed 67 times
0

Roman C
- 49,761
- 33
- 66
- 176

user2666282
- 381
- 1
- 2
- 15
-
Does A stop running soon / directly after generating the file? If so, you can just put A and B sequentially in a batch file / shell script (depending on the OS). – Bernhard Barker Aug 14 '15 at 11:14
-
@ssnobody Windows Server 2012 – user2666282 Aug 14 '15 at 18:12
-
@Dukeling then how do I know if A generated the file ? (we don't want to run B if A failed to generate the file) – user2666282 Aug 14 '15 at 18:26
-
Is there a way (in Java) for A to tell - hey the file is done - B you can run after a minute. – user2666282 Aug 14 '15 at 19:06
-
You could do this using [WMI Event Monitoring](https://technet.microsoft.com/en-us/library/Ff730927.aspx) and listening for `__InstanceCreationEvent`. If you can change the source code for both programs, then after A is done generating C.xml it could send a execute or send a message to B. Perhaps you could try directly invoking the method, using Java Message Service, or a network socket. – ThatOneDude Aug 14 '15 at 20:13
-
Call [System.exit](http://docs.oracle.com/javase/7/docs/api/java/lang/System.html#exit(int)) with a non-zero parameter to indicate that A failed and just [check for this](http://stackoverflow.com/questions/887066/how-to-get-the-exit-status-of-a-java-program-in-windows-batch-file) in your script. – Bernhard Barker Aug 15 '15 at 00:42
-
Thanks - Does any know if Jenkins can do this? Like trigger B after verifying if A has done generating C and then say wait for a minute. – user2666282 Aug 19 '15 at 22:23