Question

defmodule Math do
  def sum(a, b) do
    a + b
  end
end

I created this elixir module and created the byte code using command elixirc file.ex. I need to call the Math.sum() from another program using the bytecode. Can I call this method in a java program using

String startErlangVM = "iex";
Runtime.getRuntime().exec(startErlangVM + ";" + "Math.sum(1, 2)" );

But this isn't working. Is there any way to call a Elixir method not calling iex to start Erlang virtual machine explicitly?

Was it helpful?

Solution

I want to run a program with multi-core support. Front end is in java. But java VM doesn't support parallel programming. Only one thread will run at a time. Elixier is better in parallel programming. So I tried to create the back end using elixir. I need help on calling the elixir methods.

In this case, to use the power of concurrency, you should implement the Java front end as a TCP client. And implement the Elixir backend as a TCP server, that is handling client requests and respond with messages.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top