资源加载中... loading...

getThread

The getThread() function is used to get the thread object based on the specified thread Id.

The getThread() function returns the Thread object with the threadId specified by the parameter

Thread object

getThread(threadId)

The parameter threadId is the thread object ID. Get the corresponding thread object by specifying the parameter.

threadId true number

function main() {
    var t1 = threading.Thread(function () {
        Log("Hello thread1")
    })
    // The Thread object has a method: id(), which is used to get the thread ID. You can view the section of the document corresponding to the Thread object.
    var threadId = t1.id()
    var threadName = t1.name()
    Log("threadId:", threadId, ", threadName:", threadName)
    
    var t2 = threading.getThread(threadId)
    Log(`threadId == t2.id():`, threadId == t2.id(), `, threadName == t2.name():`, threadName == t2.name())
}

Get the specified thread object through threadId.

It supports backtesting system and live trading environment.

If the thread you want to obtain has been executed and released, you cannot use threading.getThread(threadId) to obtain the thread object of the thread.

{@fun/Threads/threading/Thread Thread}, {@fun/Threads/threading/mainThread mainThread}, {@fun/Threads/threading/currentThread currentThread}, {@fun/Threads/threading/Lock Lock}, {@fun/Threads/threading/Condition Condition}, {@fun/Threads/threading/Event Event}, {@fun/Threads/threading/Dict Dict}, {@fun/Threads/threading/pending pending}, {@fun/Threads/threading/eventLoop eventLoop}

Thread mainThread