MarketFactory provides a Zero-GC Java MFClient. Using this client enables the program to not have garbage collection pauses (given that the program using the library is written in a way that also does not generate garbage). To use this, link to MFAPI-zerogc.jar. Implementing to this library is similar to implementing to the regular library, except for the following differences:
- Once the MFClient has established a connection, it will no longer allocate memory from the heap. If there is a disconnection, then heap memory will be allocated. Therefore, if too many disconnections occur, the process should be restarted in order to avoid a GC pause. (This is dependent on how the JVM is tuned).
- The message is reused after each callback to the class implementing MFHandler. Therefore, the program must make a copy of the data in the message if it wants to use the data after the callback returns to MFClient. Keeping a reference to any data will result in errors.
- A pool of recycled messages is allocated for each MFClient. Therefore there can be multiple MFClients per process. Only one thread can run the event loop of the MFClient by calling the run(...) method. During this time, multiple threads can trade independently (by calling submit, modify, and cancel) and still be thread-safe.
- All uses of java.lang.String are replaced with MFString. This is a mutable version of java.lang.String. Therefore, all mutating methods manipulate the actual class and do not generate copies.
- MFFloat is also a mutable class. Therefore, like MFString, all mutating methods manipulate the actual class and do not generate copies.
- Many of the classes have a deepCopy() method. In order to use this properly, you must allocate memory for each of the destination's member objects and arrays as the method does not do this for you. This is because it is assumed that the user needs to control these memory allocations (usually through object pooling) in order to prevent garbage from being generated.