thread Command

MQL has a notion of a thread, where you can run multiple MQL sessions inside a single process. Each thread is like a separate MQL session, except that all threads run within the same MQL process. This concept was introduced into MQL to support the MSM idea of multiple “deferred commit” windows.

This page discusses:

User Level

System Administrators

Start Thread

By default, when you enter MQL, you are in thread number 1. You can start a new thread by running the start thread command. The command returns the ID (an integer) of the new thread. You are now in the new thread.

start thread;

If, in the previous thread, you had started a transaction and made a change to the database but had not committed it yet, the change will not be visible in the new thread. This behavior is the same as you would have if you had multiple MQL processes running and in one of them a transaction had been started and a change made.

Because application/framework/custom programs cannot guarantee that all programs have been precompiled, it is important to adhere to the following rules when using secondary threads:

  1. Keep the operations performed on the secondary thread to an absolute minimum.
  2. Never modify any objects that could possibly be in an update state due to modifications on any other transaction thread, including the main thread.
  3. Never perform any operation that could cause a JPO to be compiled, since this might cause implicit write operations for JPOs that need compiling.

Resume Thread

You can switch back to an existing thread using the resume thread command. Indicate the ID of the thread you want to resume

For example, if you are in the third thread and want to return to the first thread, use:

resume thread 1;

Print Thread

You can find out the current thread by running print thread. The ID number of the current thread is returned.

print thread;

Kill Thread

A thread other than the current one can be killed (like killing an MQL process) by using the kill thread command. Indicate the number of the thread that you want to terminate.

kill thread 2;