VirtualBox

Changeset 56625 in vbox


Ignore:
Timestamp:
Jun 24, 2015 5:18:45 PM (9 years ago)
Author:
vboxsync
Message:

doc/SDKRef: Document how to run the system event queue when using the Java binding, and make more use of it in the sample code (which already used it, and the method was already there since day 1), plus a fix in the webservice case.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/manual/en_US/SDKRef.xml

    r56544 r56625  
    38403840      SDK. It contains exception handling and error printing code, which
    38413841      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>
    38423864    </sect1>
    38433865  </chapter>
  • trunk/src/VBox/Main/glue/glue-java.xsl

    r56328 r56625  
    38923892    public void waitForEvents(long tmo)
    38933893    {
    3894         // what to do here?
    38953894        try
    38963895        {
     
    46954694    public void waitForEvents(long tmo)
    46964695    {
     4696        try
     4697        {
     4698          Thread.sleep(tmo);
     4699        }
     4700        catch (InterruptedException ie)
     4701        {
     4702        }
    46974703    }
    46984704
  • trunk/src/VBox/Main/glue/tests/TestVBox.java

    r55802 r56625  
    7373                    es.eventProcessed(listener, ev);
    7474                }
     75                mgr.waitForEvents(0);
    7576            }
    7677        } catch (Exception e) {
     
    115116            }
    116117        }
     118        mgr.waitForEvents(0);
    117119    }
    118120
     
    140142        progressBar(mgr, p, 10000);
    141143        session.unlockMachine();
     144        mgr.waitForEvents(0);
    142145    }
    143146
     
    163166            session1.unlockMachine();
    164167            session2.unlockMachine();
     168            mgr1.waitForEvents(0);
     169            mgr2.waitForEvents(0);
    165170        } finally {
    166171            mgr1.cleanup();
     
    183188            off += buf.length;
    184189        }
     190        mgr.waitForEvents(0);
    185191    }
    186192
     
    265271        }
    266272
     273        mgr.waitForEvents(0);
    267274        if (ws)
    268275        {
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette