Node:Java Threads, Previous:SPTerm and Memory, Up:Mixing Java and Prolog



Java Threads

None of the pre-3.9 methods in se.sics.jasper are thread safe. They can only be called from the thread that created the SICStus object. (This is different from how se.sics.jasper used to work in SICStus 3.8).

In 3.9 there are two ways to set up for calls to SICStus from multiple threads.

One way is to use the static method newProlog in the class Jasper:

Prolog newProlog (String argv[], String bootPath) Method on Jasper
Creates a Prolog interface object. Starts a server thread which will serve that Prolog. The server thread takes care of all interaction with the Prolog runtime, making sure that all calls to the Prolog runtime will be done from one and the same thread.

See the HTML documentation on the interface Prolog for details on what methods are available for a client thread.

Another way is to create a SICStus object and use the following methods:

Prolog newProlog () Method on SICStus
Returns the Prolog interface for this SICStus object. Creates a server and a client (Prolog) interface for this SICStus object. The server may be started by calling startServer()

startServer () Method on SICStus
Start serving requests from a Prolog client. This method does not return until another thread calls stopServer(). Before calling this method you should call newProlog() and hand the result over to another Thread.

stopServer () Method on SICStus
Stops the server. Calling this method causes the Thread running in the startServer() method to return.

As with the first method, the interface Prolog defines the methods available for the client threads.