471,599 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

How do I service a single class on one low priority thread?

Hi Everyone,

I was thinking of how to do this for a while now and I cant get my
head round it so I though I'd ask the experts! :-)

What I am doing is reading in large amounts of data over TCP and
saving it to disk. I receive alot of data from alot of clients so I do
all this without processing the data.

When a piece of data from a client has been completed I want to do
some processing on it and then send it off to another server. I want
to do all this in a low priority thread so as not to interfere with
the main program. What I would like to do is just add the job to a
queue and have a thread waiting ready to service the queue when a job
arrives. I may have 100 items on the queue or only 1. I just want this
thread to trundle away in the background pulling a job off the queue
processing it and then getting another job etc. If the queue is empty
then I would expect it to just sit there idle until an item is added.
Is this possible? How would I go about it or is there a better way?

Many thanks
Nov 17 '05 #1
3 1260
Erik <erik@[spamm1ngN0spamm1ng]scrappy.freeserve.co.uk> wrote:
I was thinking of how to do this for a while now and I cant get my
head round it so I though I'd ask the experts! :-)

What I am doing is reading in large amounts of data over TCP and
saving it to disk. I receive alot of data from alot of clients so I do
all this without processing the data.

When a piece of data from a client has been completed I want to do
some processing on it and then send it off to another server. I want
to do all this in a low priority thread so as not to interfere with
the main program. What I would like to do is just add the job to a
queue and have a thread waiting ready to service the queue when a job
arrives. I may have 100 items on the queue or only 1. I just want this
thread to trundle away in the background pulling a job off the queue
processing it and then getting another job etc. If the queue is empty
then I would expect it to just sit there idle until an item is added.
Is this possible? How would I go about it or is there a better way?


Well, see the link below for a producer/consumer queue. Then just
create a thread which is going to be the consumer, set it to be low
priority, and start it.

http://www.pobox.com/~skeet/csharp/t...eadlocks.shtml (half way
down the page)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2
Also remember that thread priority is system wide, not just application
wide. So using a lower priority may actually negatively effect your
performance. If your consumer keeps falling too behind because it is on a
lower priority, then at some point your producer(s) will out run your
consumer and either fill the queue (if bounded) or fill all memory. If your
writing to disk, this may be less of a concern. Here is an UI example I did
using my Bounded Blocking queue on Channel9:
http://channel9.msdn.com/ShowPost.aspx?PostID=50960

--
William Stacey [MVP]

"Erik" <erik@[spamm1ngN0spamm1ng]scrappy.freeserve.co.uk> wrote in message
news:k6********************************@4ax.com...
Hi Everyone,

I was thinking of how to do this for a while now and I cant get my
head round it so I though I'd ask the experts! :-)

What I am doing is reading in large amounts of data over TCP and
saving it to disk. I receive alot of data from alot of clients so I do
all this without processing the data.

When a piece of data from a client has been completed I want to do
some processing on it and then send it off to another server. I want
to do all this in a low priority thread so as not to interfere with
the main program. What I would like to do is just add the job to a
queue and have a thread waiting ready to service the queue when a job
arrives. I may have 100 items on the queue or only 1. I just want this
thread to trundle away in the background pulling a job off the queue
processing it and then getting another job etc. If the queue is empty
then I would expect it to just sit there idle until an item is added.
Is this possible? How would I go about it or is there a better way?

Many thanks

Nov 17 '05 #3
Thanks guys, this was all very useful

Thanks again

On Thu, 23 Jun 2005 20:21:49 GMT, Erik
<erik@[spamm1ngN0spamm1ng]scrappy.freeserve.co.uk> wrote:
Hi Everyone,

I was thinking of how to do this for a while now and I cant get my
head round it so I though I'd ask the experts! :-)

What I am doing is reading in large amounts of data over TCP and
saving it to disk. I receive alot of data from alot of clients so I do
all this without processing the data.

When a piece of data from a client has been completed I want to do
some processing on it and then send it off to another server. I want
to do all this in a low priority thread so as not to interfere with
the main program. What I would like to do is just add the job to a
queue and have a thread waiting ready to service the queue when a job
arrives. I may have 100 items on the queue or only 1. I just want this
thread to trundle away in the background pulling a job off the queue
processing it and then getting another job etc. If the queue is empty
then I would expect it to just sit there idle until an item is added.
Is this possible? How would I go about it or is there a better way?

Many thanks


Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Marty McDonald | last post: by
3 posts views Thread by Mike | last post: by
5 posts views Thread by Gardar | last post: by
2 posts views Thread by Tim Reynolds | last post: by
2 posts views Thread by John A | last post: by
7 posts views Thread by Joseph Geretz | last post: by
4 posts views Thread by Oriane | last post: by
2 posts views Thread by =?Utf-8?B?bXVyYWRqYW1lcw==?= | last post: by
2 posts views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

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.