Skip to content

Commit 4c5266e

Browse files
committed
Some example update.
#39
1 parent a725aef commit 4c5266e

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

docs/manual.adoc

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,60 @@ If the semaphore is garbage collected with processes waiting for it then an erro
683683

684684
=== Example
685685

686+
If you check the _interrupt_ example in the source distribution you will find it uses the SimulationEntity to model asynchronous behaviour. For instance, the Processor class, some of which is shown below:
687+
688+
----
689+
public class Processor extends SimulationEntity
690+
{
691+
public void run ()
692+
{
693+
Job j = null;
694+
695+
while (!terminated())
696+
{
697+
try
698+
{
699+
try
700+
{
701+
timedWait(sTime.getNumber());
702+
703+
if (!MachineShop.JobQ.isEmpty())
704+
{
705+
j = MachineShop.JobQ.dequeue();
706+
MachineShop.ProcessedJobs++;
707+
}
708+
}
709+
catch (InterruptedException e)
710+
{
711+
if (MachineShop.SignalQ.isEmpty())
712+
System.out
713+
.println("Error - signal caught, but no message given!");
714+
else
715+
{
716+
j = MachineShop.SignalQ.dequeue();
717+
MachineShop.SignalledJobs++;
718+
}
719+
}
720+
721+
if (MachineShop.SignalledJobs == 2)
722+
terminate();
723+
}
724+
catch (SimulationException e)
725+
{
726+
}
727+
catch (RestartException e)
728+
{
729+
}
730+
catch (IOException e)
731+
{
732+
}
733+
}
734+
}
735+
}
736+
----
737+
738+
As can be seen, the Processor uses timedWait to hold for a specified period of time but this can be interrupted by an event, in this case that a message has been delivered.
739+
686740
== Statistical classes
687741

688742
The purpose of a simulation typically involves the gathering of relevant statistical information, e.g., the average length of time spent in a queue. JavaSim provides a number of different classes for gathering such information. These classes can be found in the org.javasim.stats package.

0 commit comments

Comments
 (0)