Next: , Previous: , Up: lib-jasper   [Contents][Index]


10.19.7 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 release 3.8.)

As of 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:

Method on Jasper: Prolog newProlog (String argv[], String bootPath)

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:

Method on SICStus: Prolog newProlog ()

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()

Method on SICStus: startServer ()

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.

Method on SICStus: stopServer ()

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.



Send feedback on this subject.