Farming Model

Example – A Client Server System

This example was implemented using the concurrency library, called “Communicating Java Threads” (CTJ), in 1997. At the time, Java was a new language, which includes multithreading in the language. Still creating parallel software with threads is difficuly, even in Java. In order to make parallel programming easier and less error-prone in Java, I have created the CTJ library. CTJ is based on “Communication Sequential Processes” by C.A.R. hoare. The CTJ library provides CSP-based channels and operators for Java. CTJ turned Java into realtime Java (see note). CTJ is very closely related to the formal semantics of CSP (process algebra). In order to show that a CSP program could be implemented in Java, I took this excellent paper from Martin and Jassin and I wrote this applet in Java using CTJ. I’ve met Martin and Jassin at the WoTUG-20 (now CPA) conference in The Netherlands in 1997, where I gave a workshop. The C++ version of CTJ (called CTC++) was used to program realtime software for robots with small embedded computers for which no JVM was available. CTJ has been used a lot for education all over the world.

Paper: How to Design Deadlock-Free Networks Using CSP and Verification Tools — A Tutorial Introduction,
by J.M.R.Martin and S.A.Jassin

I have reimplemented this example with the new Waza API library. I have replace the CTJ channels with the Waza channels and it worked right away. The Waza API for Java is the successor of CTJ with new programming concepts derived from CSP. The Waza library also turns Java into realtime Java.

Note: CTJ provided the first realtime Java based on concurrency patterns. Later the JSR1 (RTSJ 1.0) specication was developed by the Java Community Process. This specification has become a monster of a specification with things you don’t need. CTJ has been recognized by Sun Microsystems for excellent and innovative research.

This page does not support applets.
We direct you to another site with the applet. The applet runs with JRE or JDK installed. Java should trust the wazalogic site otherwise it will block the applet. There is no security risk running this applet. Chrome and Microsoft Edge no longer support plugins and therefore they do not run Java applets. You should use the Internet Explorer to run the applet.

Open the Java control panel in start menu, then go to :

Security (tab) -> Edit Site List… (button) -> Add (button) -> type ‘’ + enter.

Restart your Internet Explorer, go to this page and click here. Or go directly to ‘’. If you get a popup then press the run button.

  • This example is a star network of a farmer (spider) in the center, surrounded by several foremen (critters) and many workers (dukes). The arrows are CSP channels. When a worker is doing nothing it shouts “no work!” via a channel to the foreman. The foreman listens to the worker and shouts “hey I have an idle worker!” to the farmer via a channel. The farmer responds and sends work instructions back to the foreman via a channel. The foreman receives the instructions and passes the instructions to the worker via a channel. The worker reads the instructions and carries out the work for some time. After the worker finishes the work, it holds his both hands on the hips (akimbo) and shouts “no work!” to the foreman. Again, the worker waits until it receives new instructions. The instructions can be left-handed, right-handed or both-handed work. The animation of the duke shows the type of work it is performing. The farmer just spins around and the foremen just roll their eyes to illustrate that there processes are progressing in parallel. The performance of the worker, doing its work, is shown by the speed of animation. Of course, the shouting above is a metaphor for the direction of flow of communication via channels. The channels can be seen as the air that transports the sound waves and the channel ends can be seen as the mouths and ears of the creatures in this example.
  • FarmingModel height=

The example runs 22 parallel processes and a thread to paint the sprites. This can be scaled up to hundreds of processes. The animations in this example are not very smooth because we use simple delays to slow down the animations. So this has nothing to do with the Waza API.


  • Install JRE or JDK (link)
  • Download below and unpack it.
  • Open FarmingModel/bin/Applet.html in browser (with Java plug-in support)
  • or go to FarmingModel/bin and run in command-prompt: appletviewer Applet.html

by G.H.Hilderink, Wazalogic, 2016