473,569 Members | 2,542 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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********@rog ers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #1
4 1707
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********@rog ers.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.Collecti ons.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********@rog ers.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********@rog ers.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******** ******@TK2MSFTN GP10.phx.gbl:
The main thread would add work items to a System.Collecti ons.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********@rog ers.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.Threadin g.AutoResetEven t 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 ThreadRequestQu eue

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(ByVa l 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********@rog ers.com> wrote in message
news:Xn******** *************** ****@140.99.99. 130...
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in
news:ub******** ******@TK2MSFTN GP10.phx.gbl:
The main thread would add work items to a System.Collecti ons.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********@rog ers.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
2257
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 avail!!! The EXACT same error occurs: org/apache/bsf/BSFManager Please Try The Following:
4
1663
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 increments instanceCount before the lock(staticLock)...why not inside of the lock? The MinThreads and MaxThread properties do not validate the...
12
18657
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 LEFT JOIN UserTeamAssoc UTA ON UTA.userID = U.userID, Role R, UserRoleAssoc URA, Team T WHERE U.userID = URA.userID AND URA.roleID = R.roleID AND...
8
4801
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 tell the threadpool that my method is done running and the thread is to be disposed of?
6
2737
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 event Also (failing this ThreadPool issue) is it possible to create an array of Worker Threads, can anyone illustrate with code please Thanks
5
6360
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.: ThreadPool.QueueUserWorkItem(AddressOf MyCallBack, New MyObject(myArg1, myArg2)) the new object MyObject is instantiated just before QueueUserWorkItem is called,...
1
2020
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, so I wondered if anyone had any examples of the best way to do this. I've obviously had a look myself but haven't gotten very far and although...
3
2899
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 on the java.library.path: C:\Program...
6
1624
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 be this: The processing of the received messages. Something goes wrong in this processing and the code gets stuck here. As the processing is within...
3
2977
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 will be created. So, for my example, 8 connections have been established almost all at the same time (8 Tasks object). If my server is a dual core...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8125
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7676
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1221
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.