Changeset 56625 in vbox
- Timestamp:
- Jun 24, 2015 5:18:45 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/manual/en_US/SDKRef.xml
r56544 r56625 3840 3840 SDK. It contains exception handling and error printing code, which 3841 3841 is important for reliable larger scale projects.</para> 3842 3843 <para>It is good practice in long-running API clients to process the 3844 system events every now and then in the main thread (does not work 3845 in other threads). As a rule of thumb it makes sense to process them 3846 every few 100msec to every few seconds). This is done by 3847 calling<programlisting> 3848 mgr.waitForEvents(0); 3849 </programlisting> 3850 This avoids that a large number of system events accumulate, which can 3851 need a significant amount of memory, and as they also play a role in 3852 object cleanup it helps freeing additional memory in a timely manner 3853 which is used by the API implementation itself. Java's garbage collection 3854 approach already needs more memory due to the delayed freeing of memory 3855 used by no longer accessible objects, and not processing the system 3856 events exacerbates the memory usage. The 3857 <computeroutput>TestVBox.java</computeroutput> example code sprinkles 3858 such lines over the code to achieve the desired effect. In multi-threaded 3859 applications it can be called from the main thread periodically. 3860 Sometimes it's possible to use the non-zero timeout variant of the 3861 method, which then waits the specified number of milliseconds for 3862 events, processing them immediately as they arrive. It achieves better 3863 runtime behavior than separate sleeping/processing.</para> 3842 3864 </sect1> 3843 3865 </chapter> -
trunk/src/VBox/Main/glue/glue-java.xsl
r56328 r56625 3892 3892 public void waitForEvents(long tmo) 3893 3893 { 3894 // what to do here?3895 3894 try 3896 3895 { … … 4695 4694 public void waitForEvents(long tmo) 4696 4695 { 4696 try 4697 { 4698 Thread.sleep(tmo); 4699 } 4700 catch (InterruptedException ie) 4701 { 4702 } 4697 4703 } 4698 4704 -
trunk/src/VBox/Main/glue/tests/TestVBox.java
r55802 r56625 73 73 es.eventProcessed(listener, ev); 74 74 } 75 mgr.waitForEvents(0); 75 76 } 76 77 } catch (Exception e) { … … 115 116 } 116 117 } 118 mgr.waitForEvents(0); 117 119 } 118 120 … … 140 142 progressBar(mgr, p, 10000); 141 143 session.unlockMachine(); 144 mgr.waitForEvents(0); 142 145 } 143 146 … … 163 166 session1.unlockMachine(); 164 167 session2.unlockMachine(); 168 mgr1.waitForEvents(0); 169 mgr2.waitForEvents(0); 165 170 } finally { 166 171 mgr1.cleanup(); … … 183 188 off += buf.length; 184 189 } 190 mgr.waitForEvents(0); 185 191 } 186 192 … … 265 271 } 266 272 273 mgr.waitForEvents(0); 267 274 if (ws) 268 275 {
Note:
See TracChangeset
for help on using the changeset viewer.