|
@@ -1,4 +1,31 @@
|
|
|
|
|
|
+<h3><a>The jME3 Threading Model</a></h3>
|
|
|
+<div>
|
|
|
+
|
|
|
+<p>
|
|
|
+
|
|
|
+jME3 is similar to Swing in that for speed and efficiency all changes to the world must be made in a single update thread. This is handled automatically for you if using Controllers or simpleUpdate however whenever you pass work to another thread you need to hand the results back to the main jME3 thread before making any changes to the scene graph.
|
|
|
+</p>
|
|
|
+<pre> public void rotateGeography(final Geography goe, final Quaternian rot) {
|
|
|
+ mainApp.enqueue(new Callable<Spatial>() {
|
|
|
+
|
|
|
+ public Spatial call() throws Exception {
|
|
|
+ return geo.rotate(rot);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ }</pre>
|
|
|
+
|
|
|
+<p>
|
|
|
+Note that this example does not fetch the returned value by calling <code>get()</code> on the Future object returned from <code>enqueue()</code>. This means that the example method <code>rotateGeography()</code> will return immediately and will not wait for the rotation to be processed before continuing.
|
|
|
+</p>
|
|
|
+
|
|
|
+<p>
|
|
|
+If the processing thread needs to wait or needs the return value then <code>get()</code> or the other methods in the returned Future object such as <code>isDone()</code> can be used.
|
|
|
+</p>
|
|
|
+
|
|
|
+</div>
|
|
|
+<!-- EDIT1 SECTION "The jME3 Threading Model" [1-1116] -->
|
|
|
<h1><a>Multithreading Optimization</a></h1>
|
|
|
<div>
|
|
|
|
|
@@ -20,7 +47,7 @@ Effectively, each for-loop in the main update loop might be a chance for multith
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
-<!-- EDIT1 SECTION "Multithreading Optimization" [1-1132] -->
|
|
|
+<!-- EDIT2 SECTION "Multithreading Optimization" [1117-2248] -->
|
|
|
<h2><a>Java Multithreading</a></h2>
|
|
|
<div>
|
|
|
|
|
@@ -39,7 +66,7 @@ The java.util.concurrent package provides a good foundation for multithreading a
|
|
|
</ul>
|
|
|
|
|
|
</div>
|
|
|
-<!-- EDIT2 SECTION "Java Multithreading" [1133-2205] -->
|
|
|
+<!-- EDIT3 SECTION "Java Multithreading" [2249-3321] -->
|
|
|
<h2><a>Multithreading in jME3</a></h2>
|
|
|
<div>
|
|
|
|
|
@@ -57,7 +84,7 @@ To avoid slowdown, we decide to keep the pathfinding operations in the NPC Contr
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
-<!-- EDIT3 SECTION "Multithreading in jME3" [2206-2878] -->
|
|
|
+<!-- EDIT4 SECTION "Multithreading in jME3" [3322-3994] -->
|
|
|
<h3><a>Executor</a></h3>
|
|
|
<div>
|
|
|
|
|
@@ -84,7 +111,7 @@ In your simple application you can override the stop method and shutdown the exe
|
|
|
}</pre>
|
|
|
|
|
|
</div>
|
|
|
-<!-- EDIT4 SECTION "Executor" [2879-3946] -->
|
|
|
+<!-- EDIT5 SECTION "Executor" [3995-5062] -->
|
|
|
<h3><a>Control Class Fields</a></h3>
|
|
|
<div>
|
|
|
|
|
@@ -104,7 +131,7 @@ Here we also created the Future variable to track the state of this task.
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
-<!-- EDIT5 SECTION "Control Class Fields" [3947-4537] -->
|
|
|
+<!-- EDIT6 SECTION "Control Class Fields" [5063-5653] -->
|
|
|
<h3><a>Control Update() Method</a></h3>
|
|
|
<div>
|
|
|
|
|
@@ -152,7 +179,7 @@ Remember not to mess with the class fields after starting the thread, because th
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
-<!-- EDIT6 SECTION "Control Update() Method" [4538-6408] -->
|
|
|
+<!-- EDIT7 SECTION "Control Update() Method" [5654-7524] -->
|
|
|
<h3><a>The Callable</a></h3>
|
|
|
<div>
|
|
|
|
|
@@ -204,34 +231,7 @@ private Callable<MyWayList> findWay = new Callable<MyWayList>(&#
|
|
|
};</pre>
|
|
|
|
|
|
</div>
|
|
|
-<!-- EDIT7 SECTION "The Callable" [6409-8776] -->
|
|
|
-<h3><a>The jME3 Threading Model</a></h3>
|
|
|
-<div>
|
|
|
-
|
|
|
-<p>
|
|
|
-
|
|
|
-jME3 is similar to Swing in that for speed and efficiency all changes to the world must be made in a single update thread. This is handled automatically for you if using Controllers or simpleUpdate however whenever you pass work to another thread you need to hand the results back to the main jME3 thread before making any changes to the scene graph.
|
|
|
-</p>
|
|
|
-<pre> public void rotateGeography(final Geography goe, final Quaternian rot) {
|
|
|
- mainApp.enqueue(new Callable<Spatial>() {
|
|
|
-
|
|
|
- public Spatial call() throws Exception {
|
|
|
- return geo.rotate(rot);
|
|
|
- }
|
|
|
-
|
|
|
- });
|
|
|
- }</pre>
|
|
|
-
|
|
|
-<p>
|
|
|
-Note that this example does not fetch the returned value by calling <code>get()</code> on the Future object returned from <code>enqueue()</code>. This means that the example method <code>rotateGeography()</code> will return immediately and will not wait for the rotation to be processed before continuing.
|
|
|
-</p>
|
|
|
-
|
|
|
-<p>
|
|
|
-If the processing thread needs to wait or needs the return value then <code>get()</code> or the other methods in the returned Future object such as <code>isDone()</code> can be used.
|
|
|
-</p>
|
|
|
-
|
|
|
-</div>
|
|
|
-<!-- EDIT8 SECTION "The jME3 Threading Model" [8777-9892] -->
|
|
|
+<!-- EDIT8 SECTION "The Callable" [7525-9891] -->
|
|
|
<h2><a>Conclusion</a></h2>
|
|
|
<div>
|
|
|
|
|
@@ -250,5 +250,5 @@ The cool thing about this approach is that every entity creates one self-contain
|
|
|
</span></div>
|
|
|
|
|
|
</div>
|
|
|
-<!-- EDIT9 SECTION "Conclusion" [9893-] -->
|
|
|
+<!-- EDIT9 SECTION "Conclusion" [9892-] -->
|
|
|
<p><em><a href="http://jmonkeyengine.org/wiki/doku.php/jme3:advanced:multithreading?do=export_xhtmlbody">view online version</a></em></p>
|