Examples

All example sources can be downloaded from the download page.

Example 1

In this example three service threads send each other three communication queue items.
Each item sends another item to the next service: 1 -> 2 -> 3 -> 1 etc.

InfoBusTest1.java
PassTo1CommQueueItem.java
PassTo2CommQueueItem.java
PassTo3CommQueueItem.java


Example 2

This example is similar to the previous one, but there is only one communication queue item. In the constructor it receives the number of service to send the next item to.

InfoBusTest2.java
PassToNextCommQueueItem.java


Example 3

This is the most interesting example. It solves the Dining Philosophers problem for an arbitrary number of philosophers. See comments in the InfoBusTestDinner.java for the detailed explanation.
The example was tested for 1000 service threads, each one serving one philosopher. You can change the PHILOSOPHERS_NUMBER constant to test any other situation.
The logic of a philosopher's behavior is encapsulated in the WakeUpCommQueueItem communication queue item.

InfoBusTestDinner.java
Philosopher.java
Table.java
WakeUpCommQueueItem.java