[erlang-questions] Reliable way to handle Java node crashs?

Garrett Smith <>
Thu Jun 17 16:10:19 CEST 2010

Hi Zanrane,

On Thu, Jun 17, 2010 at 8:45 AM, zabrane Mikael <> wrote:
> Hi List,
> I've a java node waiting for some "data messages" from an Erlang node.
> As soon as a "data message" arrives, it gets processed by this Java node
> (very intensive data processing).
> Occasionally, this Java node crashes during the processing phase and the
> Erlang node never gets back any response. All my system hangup.
> The Erlang part can send only one message at any time and must wait for a
> response before sending the next one (this is my current design of the
> system)
> to the Java node.
> Questions:
> 1. How can i start my "Java node" automatically from within Erlang?
> Currently, I'm running the Java node manually on a separate shell, wait for
> it to open
> its mailbox. Then, i run the Erlang code in another shell. This is a real
> nightmare to handle the "restarts" manually when the Java node crashes.

Why not launch the Java process from an Erlang supervisor and monitor
its process with a port?

I haven't worked with Java based Erlang nodes myself -- I use the port
interface, which has worked very well.

You need to deal with mashalling message payload, but I imagine
Erlang's Java library provides some help there. If not, there's the
standby of Json, XML, CSV, etc.

> 2. What's the best way to robustify my Java node so it'll never stop even
> after a crash? The ideal for me is to get it send back an {error, Reason}
> message
> to Erlang node and wait for a next message to process.

If you supervise the external (system) process via an Erlang port,
you'll get the restart behavior that recovers the Java app on a crash.

If you take this approach, you'll want to "crash" your Java process on
unhandled errors (i.e. System.exit() to terminate the process). The
supervisor monitoring the port will detect this and restart the Java
app (via the port) as per its restart spec.

> Code snippet will be very welcome guys !
> Thanks in advance
> --
> Regards
> Zabrane


More information about the erlang-questions mailing list