コード例 #1
0
func Test_threadPool(t *testing.T) {

	threadPool := Create()
	threadPool.Init()

	test := new(Test)

	thread1 = msgThread.Create()
	thread1.Init()
	thread1.Tag = "111"
	thread1.SetThreadCallBack(test.MyThreadCallBack1)
	thread1.SetMsgCallBack(test.MyThreadMsgCallBack1)
	thread1.SetWaitMode(false)
	threadPool.Add(thread1)

	thread2 = msgThread.Create()
	thread2.Init()
	thread2.Tag = "222"
	thread2.SetThreadCallBack(test.MyThreadCallBack2)
	thread2.SetMsgCallBack(test.MyThreadMsgCallBack2)
	thread2.SetWaitMode(false)
	threadPool.Add(thread2)

	threadPool.SetWaitMode(false)
	threadPool.SetCallBack(test.MyThreadPoolCallBack)
	threadPool.Start()

	threadPool.SetWaitMode(true)
	threadPool.Wait()
}
コード例 #2
0
func (this *TcpServer) createHandlerThread(conn net.Conn) *msgThread.Thread {

	handleThread := msgThread.Create()
	handleThread.Init()
	SetConnection(handleThread, conn)
	handleThread.SetThreadCallBack(this.handleConnectionThreadProc)
	handleThread.SetMsgCallBack(this.clientThreadMsgProc)
	handleThread.Start()

	return handleThread
}