Multithread Considerations

The server runs channels and process flows in full multithread and multiprocessor modes to the degree configured and for which hardware is available. The following list shows the normal rules of multithread programming that are applied:

Java language provides facilities to assist in this, and many books are available to provide advice.

Testing a multithread program is often difficult, as it is hard to simulate the many possible interactions between threads and with the hardware or operating system that result in "scrambling" of the order of execution. The bugs that arise are often referred to, jokingly, as Heisenbugs, as they seem to vanish when an attempt is made to search for them. The server provides a small utility to assist in the search for such tasks.

The com.ibi.xdutils package provides a simple method to cause random, distributed thread yields. It is discussed here as it may assist programmers in testing software and in developing their own, more sophisticated, and application-specific approaches.

The assert statement must be added to the code as shown below:

assert(com.ibi.xdutils.XDAssert.heisenbug())

This causes a random thread yield by issuing a Sleep for a short, random millisecond period. To enable this code, add -ea (-enableassertions) to the startup command for Java in the server start script.

If assertions are not enabled, the assert statement is ignored by the Java Virtual machine. The asserts can be left in the application code and enabled as needed without causing a significant production overhead.

Problems caused by bugs in multithread handling often become apparent by scrambling the order of the thread execution.


iWay Software