Prey-Predators in
Java
Preys are blue and are running away from predators which are red.
Predators are pursuing preys and kill them when they succed to catch
them. Preys and predator have a restricted visibility area and are
randomly moving when there is nothing in it.
Preys and predators extend the class
Icobj and applets extend the class
IcobjWorkspace. Preys are
instances of class Prey and predators
are instances of class Predator.
Initially, there are 50 preys and two predators. These numbers can be
changed from a little control panel which appears on screen. Demos
are started by clicking in the start button in the control panel.
In the non-thread version, all preys and predators are run by one
unique thread. Here is the mono threaded applet with its
code.
In the milti-threaded version, each prey and each predator is run by
its own thread. Here is the multi threaded applet with its
code.
One can see that the multi-threaded applet is less efficient as the
number of preys and predators becomes larger.
This example shows that threads are not well suited to
concurrent systems with a large number of small sized components.