Skip to content
All library documents

Using System Threads for Concurrent JavaScript Strategy Tasks

Article FMZ digest · Author: 发明者量化-小小梦

Summary

The document explains system-level thread support for JavaScript strategies on the FMZ platform. It distinguishes creating a separate thread to run a function from the platform’s existing asynchronous exchange calls. The examples demonstrate launching functions concurrently, waiting for completion and collecting return values, terminating a running thread, and obtaining a thread identifier. A pair of HTTP requests illustrates how independent tasks can be started together and joined afterward.

It also covers communication through messages between the main thread and worker threads, including direct thread-to-thread messaging, and sharing thread-local data through keyed storage. These mechanisms can help organize independent tasks in a strategy, such as parallel requests or background work. The document is a feature guide with code demonstrations rather than a trading method or performance study. It does not discuss synchronization hazards, resource limits, exchange-specific behavior, or how to handle failures and timeouts in production, so strategy authors would need to account for those concerns in their own designs.

Key ideas

  • A system thread can run a custom JavaScript function concurrently with the main strategy flow.
  • Joining a thread waits for completion and returns information about its execution and result.
  • A strategy can terminate a worker thread before it finishes and reclaim its resources.
  • Threads can exchange messages, with the main thread identified separately from worker threads.
  • Thread-associated storage provides another way to share keyed values across strategy threads.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.