473,382 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Using ThreadPool

Is there a document online which details the advantages of using a
Threadpool?

My application uses a user configuration amount of threads which does the
following:
Main Thread Gives Work to Sub Thread
Sub Thread Import/Export Record
Sub Thread Import/Export Record
etc...

Once the thread is down its job, the thread exists. The Main Thread
(application) continues running until a timer hits, and the process is
repeated.

Does it make sense to use a threadpool? My threads exit after their work is
complete. Typically I have 1 or 2 sub threads running and about 50+ work
items.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #1
4 1690
Lucas,

Did you see this answer Jay has sand last month?

I thought your question is at the bottom, he write it real nice in my
opinion.

http://groups.google.com/groups?selm...TNGP09.phx.gbl

Cor

"Lucas Tam"
Is there a document online which details the advantages of using a
Threadpool?

My application uses a user configuration amount of threads which does the
following:
Main Thread Gives Work to Sub Thread
Sub Thread Import/Export Record
Sub Thread Import/Export Record
etc...

Once the thread is down its job, the thread exists. The Main Thread
(application) continues running until a timer hits, and the process is
repeated.

Does it make sense to use a threadpool? My threads exit after their work is complete. Typically I have 1 or 2 sub threads running and about 50+ work
items.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 21 '05 #2
Lucas,
In addition to Cor's & other comments:

Jon Skeet has a number of articles on threads & thread pools. They are in
C#, however they should be easily converted to VB.NET.

http://www.yoda.arachsys.com/csharp/threads/

http://www.yoda.arachsys.com/csharp/threadstart.html

There is an alternative thread pool here, allowing you to limit the number
of threads to two.
http://www.yoda.arachsys.com/csharp/miscutil/
Once the thread is down its job, the thread exists. The Main Thread
(application) continues running until a timer hits, and the process is
repeated. Creating threads can be expensive. If you only have 2 "threads" running at a
time, I would consider only having 2 threads, in addition to the main
thread.

The main thread would add work items to a System.Collections.Queue, the 2
worker threads would read work items from the queue in a loop. When a worker
thread is done with one work item, it would loop back & read another item.

Hope this helps
Jay

"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@140.99.99.130.. . Is there a document online which details the advantages of using a
Threadpool?

My application uses a user configuration amount of threads which does the
following:
Main Thread Gives Work to Sub Thread
Sub Thread Import/Export Record
Sub Thread Import/Export Record
etc...

Once the thread is down its job, the thread exists. The Main Thread
(application) continues running until a timer hits, and the process is
repeated.

Does it make sense to use a threadpool? My threads exit after their work
is
complete. Typically I have 1 or 2 sub threads running and about 50+ work
items.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 21 '05 #3
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in
news:ub**************@TK2MSFTNGP10.phx.gbl:
The main thread would add work items to a System.Collections.Queue,
the 2 worker threads would read work items from the queue in a loop.
When a worker thread is done with one work item, it would loop back &
read another item.


Hmmm that's a good idea too. Never thought of that : )

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #4
Lucas,
Here is a prior post I made regarding this subject.

Normally I have a single worker thread, Looking at my code below, I believe
it will work with multiple worker threads.
For Queue I normally use a System.Threading.AutoResetEvent along with the
Queue. Depending on the parameters you pass to the AutoResetEvent.WaitOne
method, the background thread will sleep indefinitely waiting for the event
to be signaled.

The background thread has two loops. The outer loop does an
AutoResetEvent.WaitOne waiting for the event to be signaled. When the event
is signaled the background thread has an inner loop processing each item in
the queue.

When other threads put work items into the queue they Set the above
AutoResetEvent, letting the background thread know there is at least one
item in the queue.

Normally I put the Thread, the AutoResetEvent, the Queue and the padlock for
the Queue into a single class that represents the "Worker". Encapsulating
the above into clean type safe methods.

Something like:

' untested, typed from memory.
Public Class ThreadRequestQueue

Private Readonly m_padlock As New Object
Private Readonly m_queue As New Queue
Private Readonly m_event As New AutoResetEvent(False)

Public Sub AddRequest(ByVal request As Object)
SyncLock m_padlock
m_queue.Enqueue(Object)
End SyncLock
m_event.Set()
End Sub

Public Function GetRequest() As Object
' Check to see if there are already items available
SyncLock m_padlock
If m_queue.Count() > 0 Then
Return m_queue.DeQueue()
End If
End SyncLock

' Cannot block main thread
' while waiting for the main thread to add requests
' hence no SyncLock here
m_event.WaitOne()

' There must be an item
SyncLock m_padlock
Return m_queue.Dequeue()
End SyncLock
End Function

End Class

Hope this helps
Jay

"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@140.99.99.130.. .
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in
news:ub**************@TK2MSFTNGP10.phx.gbl:
The main thread would add work items to a System.Collections.Queue,
the 2 worker threads would read work items from the queue in a loop.
When a worker thread is done with one work item, it would loop back &
read another item.


Hmmm that's a good idea too. Never thought of that : )

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Phil Powell | last post by:
Ok, I installed ANT, I have c:\ant in my ANT_HOME environment variable, I have c:\ant\bin in my PATH environmental variable, I installed the JAR files for TCL and for Javascript (Rhino)... to no...
4
by: David Levine | last post by:
Jon, I've taken a look at it and these comments are based on a code-inspection but I did not verify the correctness if its operation by using it in a sample. The ctor for CustomThreadPool...
12
by: Phil Powell | last post by:
<cfquery name="getAll" datasource="#request.dsn#"> SELECT U.userID, U.fname, U.lname, U.phone, U.lastLoggedIn, U.choiceId, U.experience, T.label AS teamLabel, R.label AS roleLabel FROM User U...
8
by: memememe | last post by:
We are queueing stuff on the thread pool and what we are queueing gets done pretty quick (the method returns fine) but yet its only allowed to run around 25 times, is there anything I need to do to...
6
by: Max Adams | last post by:
Threads and ThreadPool's If I use a ThreadPool how can I tell when a thead in the threadpool has exited? I don't want to set a global member variable I would much rather be able to act on an...
5
by: Henri | last post by:
Might sound a stupid question but need to be sure: When you call ThreadPool.QueueUserWorkItem and ThreadPool.RegisterWaitForSingleObject passing a New object as state e.g.:...
1
by: colinjack | last post by:
Hi All, I've been using the original (non-event based) asynchronous design pattern using delegates. It works fine but performance wise I know using the ThreadPool is supposed to be far better,...
3
by: arasub | last post by:
ep 20, 2007 11:25:57 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found...
6
by: Ricardo Vazquez | last post by:
Hello everybody, I'm programming a TCP server. During the stress tests I noticed that maybe my socket-receiving thread became deaf after an hour of heavy stress. I think that the reason could...
3
by: Steven Blair | last post by:
I have been watching an MSDN video on the PFX Task class and have a question. Here is my scenario: TcpListener waits on incoming connections. Once a new connection is established, a new Task...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.