MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Mathematica as a server via J/Link

  • To: mathgroup at
  • Subject: [mg68876] Mathematica as a server via J/Link
  • From: "Davide" <davide.fanchini at>
  • Date: Tue, 22 Aug 2006 05:20:04 -0400 (EDT)
  • Sender: owner-wri-mathgroup at


is there anyone who could help me with some issues (or signal some good
documentation) regarding Mathematica as a server via J/Link?

More specifically, I want to use Mathematica as a server for a
multithreaded Java application, and I would like to set up a listening
MathLink object and make Java clients connect to it with the method:

ml = MathLinkFactory.createKernelLink("-linkmode connect -linkprotocol
tcpip -linkname 1234@localhost");

To make the listening MathLink I execute the following instruction from
a cmd shell:

math -mathlink -linkmode listen -linkname 1234 -linkprotocol tcpip

And I see the process hanging, waiting for a connection.

Then I run the in the documentation, obtaining the
KernelLink with:

ml = MathLinkFactory.createKernelLink("-linkmode connect -linkprotocol
tcpip -linkname 1234@localhost");

It executes correctly, but when it exits the main method I see that the
execution of math.exe is terminated (even if I comment out the line
ml.close() in the finally clause), and in fact a further execution of
the SampleProgram.main() gives the error "Not enough memory to create
Mark". I suppose this is due to the fact that the listening MathLink is
no longer present.

I've seen that if I execute the MathLinkFactory.createKernelLink() with
the "-linkmode launch", a new MathKernel instance is run for every
client, and this doesn't seem to be the right approach for a
"Mathematica server": I'd like to set up a single "listening kernel"
which could accept requests to connect by clients, with a KernelLink
for each multithreaded client. Maybe this is not correct (each client
needs its own MathKernel instance)?

I'm missing some details about the architecture, but I've not found yet
the right "piece of documentation".

Any help would be greatly appreciated.


  • Prev by Date: Re: Trigonometric simplification
  • Next by Date: Re: Re: List Help Needed
  • Previous by thread: Linear Programming Question
  • Next by thread: Installing Mathematica via SMS