getThread()
函数用于根据指定的线程Id获取线程对象。
getThread()
函数返回通过参数指定threadId的Thread
对象
Thread
对象
getThread(threadId)
参数threadId
为线程对象Id,通过指定参数获取对应的线程对象。
threadId true number
function main() {
var t1 = threading.Thread(function () {
Log("Hello thread1")
})
// Thread 对象有方法:id(),用于获取线程的Id,可以查看文档对应Thread对象的章节
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())
}
通过threadId
获取指定的线程对象。
支持回测系统、实盘环境。
如果期望获取的线程已经执行完毕、释放,此时无法通过threading.getThread(threadId)
获取该线程的线程对象。
{@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