A gear simulation in Scala
A simulation of gears using actors and scala-swing with Scala 2.8.final. To get familiar with the scala actors I wrote a small simulation:
- The ActorApplication creates 40 gears with random speed.
- The controller calculates a synchronization speed and starts the gear-actors.
- The gears synchronize to this given speed step by step (1+ or 1-).
- The simulation is finished when all gears have reached the synchronization speed.
- It's possible to manipulate the working gears with a sabotage-function.
Interesting side effects
The simulation runs well on Java JRE 1.5: all gears are working simultaneously. If you change to Java JRE 1.6 only 2-3 gears are working simultaneously instead of 40. see http://stackoverflow.com/questions/2288723/scala-actors-different-behavior-on-jre-1-5-and-1-6
Easy start in IDEA IntelliJ
If you want use IDEA IntelliJ just open the project and switch the run configuration
Debug configuration for IDEA IntelliJ
- Create new Run-Configuration (select Application)
- Use ch.clx.geargui.GearGUI as mainclass
- disable "make" before launch
- enable "maven goal" before launch: compile
- Use debug-button in IDEA
Easy start with maven
- Open the setEnv.cmd in the project directory in an editor. Change this line: set JAVA_HOME=
(JAVA_HOME should point to JDK 1.5 or JDK 1.6)
- Open a command line (cmd) and change to the project directory
- run the following command: setEnv.cmd
- run the following command (The application will start): mvn
- for changing the JDK just edit the setEnv.cmd and start at step 2 again.
Full configuration for windows
An alternative configuration is to change the PATH environment variable:
- define a new variable for JDK 1.5 i.E. Variable name: JAVA_HOME_15 Variable value: C:\Java\jdk1.5.0_21
- define a new variable for JDK 1.6 i.E. Variable name: JAVA_HOME_16 Variable value: C:\Java\jdk1.6.0_16
- use the normal JAVA_HOME variable for switching i.E. Variable name: JAVA_HOME Variable value: %JAVA_HOME_15% change the value in %JAVA_HOME% to %JAVA_HOME_16% for using JDK/JRE 1.6
- make sure that the normal %JAVA_HOME% is in your path-var at first position. For more informations: http://forums.sun.com/thread.jspa?messageID=9633247#9633247
- you can now run the project with maven: mvn
(default goal in pom.xml is set to scala:run)
- Added option ResizableThreadPoolScheduler and minor enhancements and bugfixes in GearGUI.scala
- Replace all println with a logging util