Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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. – Szabolcs Nov 11 '13 at 16:34

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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