imit_model / AnyLogic / UsersManual(AnyLogic)
.pdfAnyLogic V User’s Manual
Figure 186. Options dialog box. Build page
On the Build page of the Options dialog box, you specify paths to the Java compiler, Java virtual machine and packager used and optionally some compiler and Java VM options.
Compiler executable file name - the full path to Java compiler, e.g. C:\j2sdk1.4.0\bin\javac.exe.
Java VM file name – the full path to Java virtual machine dynamic link library (e.g. C:\j2sdk1.4.0\jre\bin\client\jvm.dll).
Packager – the full path to Java packager (e.g. C:\j2sdk1.4.0\bin\jar.exe).
Engine library file name – the full path to AnyLogic simulation engine library
(e.g. C:\Program Files\XJ\AnyLogic5.0\Lib\xjanylogic5engine.jar).
Compiler options – [optional] options passed to Java compiler. If JDK compiler is used, compiler options are usually not needed.
© 1992-2004 XJ Technologies http://www.xjtek.com |
427 |
AnyLogic V User’s Manual
22.2.2Model termination order
The model destruction is performed in the following order:
1.The model destruction starts at the root object, where the method destroy() is called. For each active object the method destroy() performs the following steps:
2.The user-defined method cleanup() is called
3.All activities (statecharts, timers, etc) are stopped
4.The method destroy() is called for all encapsulated objects recursively
5.All active object elements (ports, variables, activities, animation, etc) are deleted
6.The method onDestroy() is called for the active object.
Since the method cleanup() is called prior to the recursion, it is first called for root object and then for all object down the tree. On the other hand, the method onDestroy() is called after the recursion, therefore it is first called on leaf objects and then up the tree.
© 1992-2004 XJ Technologies http://www.xjtek.com |
429 |
Chapter 23. Threads
23. Threads
You can implement an activity in a Java method and run it in a separate thread within an active object. Threads are less visual than statecharts or timers, but in rare cases, they may provide for more natural representation of some algorithms. In general, however, if the activity has a set of states with different reactions to events, make it a statechart.
If there are no synchronization operations in the behavior (it is a pure computation), then you can call it from other places; e.g., from ports or from actions of states and transitions, and you do not need to run it in a separate thread.
To run an activity implemented in a Java method, you need to:
•Define method of an active object class with the return type void. This method will run as thread. The method can be defined e.g. in the code section Additional class code.
•Call method startThread() of the active object supplying the name of the defined method as a string.
The thread runs concurrently with all other activities (statecharts, timers). If it does not wait for anything, it terminates taking zero model time.
AnyLogic provides the following API to work with synchronization and time (for more information please consult AnyLogic Class Reference):
Related methods of ActiveObject
void startThread( String methodName ) – creates a new simple thread based on the method name of this ActiveObject.
void delay( double timeout ) – suspends the thread for the specified amount of time.
Related methods of PortQueuing
Object waitForMessage() – suspends the thread until there is a message in the port queue. Extracts the message and returns it.
430 |
© 1992-2004 XJ Technologies http://www.xjtek.com |
AnyLogic V User’s Manual
Object waitForMessage( double timeout ) – same as above, but with a timeout. On timeout returns null.
Example
In the example shown in Figure 187 the thread performs an infinite loop: it waits for the message arrival, then makes 10 time units delay.
|
Startup code: |
|
startThread( "funcActivity" ); |
MyClass |
Additional class code: |
public void funcActivity() { |
|
port |
traceln( "Start" ); |
while( true ) { |
|
|
traceln( "Step 1" ); |
|
port.waitForMessage(); |
|
traceln( "Step 2" ); |
|
delay( 10 ); |
|
} |
|
} |
|
Figure 187. Thread |
© 1992-2004 XJ Technologies http://www.xjtek.com |
431 |