Availability of threads in a thread pool?

JAMy

New Member
How to find 60%(Or N%) availability of threads from a thread pool?What is the logic behind this?
Parent thread spawning multiple urls using thread pool threads and waiting for the completion of all child threads.Code is given below;
Parent Thread
\[code\] public void Save() { List<Job> Jobs = PickJobs(); int workerThreads = 0,compThreads = 0; ThreadPool.GetMinThreads(workerThreads, compThreads); int requiredThreads = 15; ThreadPool.SetMaxThreads(requiredThreads, compThreads); WaitCallback waitCallBack = default(WaitCallback); ManualResetEvent mEvent = default(ManualResetEvent); foreach (Job _job in Jobs) { waitCallBack = new WaitCallback(CallBackFunc); mEvent = new ManualResetEvent(false); events.Add(mEvent); ThreadPool.QueueUserWorkItem(waitCallBack, new UrlData(_job, mEvent, HttpContext.Current)); } WaitHandle.WaitAll(events.ToArray(), 300000);//05 Minutes }\[/code\]
Child Threads\[code\]private void CallBackFunc(object obj){ UrlData msgObj = (UrlData)obj; WebRequest lWebRequest = WebRequest.Create(psUrl); lWebRequest.Timeout = 60000; WebResponse lWebResponse = lWebRequest.GetResponse; msgObj.FinishEvent.Set();}\[/code\]
Object data for communication across threads\[code\]public class UrlData{public Job job;public ManualResetEvent FinishEvent;public HttpContext HttpContextRef;public UrlData(Job pJob, ManualResetEvent pEvent, HttpContext pContext) { job= pJob; FinishEvent = pEvent; HttpContextRef = pContext; }}\[/code\]
In above code, the required threads are hard coded as:\[code\]int requiredThreads = 15;ThreadPool.SetMaxThreads(requiredThreads, compThreads);\[/code\]Will this hard coding leads to threadpool starvation? And what happens if no threads are available in threadpool? How to find the total number of threads available in a threadpool in a hosting server?Thanks.
 
Back
Top