Thanks, Bruce.
In practice, having the thread limit that way causes the system to hang as it continually bumps its head on that upper limit. It works out better to have a High limit and a lower release or reopen level.
We count the threads the same way but we have it like this in the StartNewThread embed. The Traces can be left out - I use them to see how often and how long the server is busy.
SELF._Trace('WebServer Mem: Threads:'&ThreadCnt&' /Max:'&MaxThreads)
If (g:ThreadHighLimit > 0 AND Threadcnt >= g:ThreadHighLimit)
g:NoService = TRUE
END
IF g:NoService AND ThreadCnt =< g:ThreadReopenLevel
g:NoService = FALSE
END
IF g:NoService
SELF._Trace('No Service Threads='&ThreadCnt&' /Max:'&g:ThreadHighLimit&' - Not processing this request')
self.senderror(500,'Server Busy','Server Busy, try again shortly')
Return
End
HTH
Chris