Is it possible to get a callback from J/Link into java when the (remote) link closes or the Mathematica process is terminated (killed) altogether?

  • 2
    $\begingroup$ Before the Mathematica process terminates, it evaluates the variable $Epilog. You can try that if you don't find anything better that's designed for J/Link. $\endgroup$
    – Szabolcs
    Commented Nov 11, 2013 at 16:34

1 Answer 1


Unless you require to-the-millisecond notification of the link going down I'd recommend polling/heart-beating the connection from the java side, say once a second, with something like 1+1 as an input and checking for 2 in the response (or if you're truly paranoid generate two random integers in java on each call, add them in mathematica and check the answer java).

This is robust, it will tell you in a second if the link is broken for any reason. A message from the mathematica process when it shuts down will only get to you (your java process that is) if it shuts down cleanly but may not if the mathematica process has been killed or died abruptly for some reason...

  1. No one has pulled out the power.
  2. Tripped over the network cable.
  3. Poured coffee in the machine...

Polling gets round all of these.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.