• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Threads when they are done

Explorer ,
Apr 18, 2008 Apr 18, 2008

Copy link to clipboard

Copied

Let's say I launch a thread without joining it to the current page thread, what happens to it when it's done?

I'm assuming it stays in memory until the GC comes and cleans it out? How long would that take? Probably a setting in CF?
TOPICS
Advanced techniques

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 19, 2008 Apr 19, 2008

Copy link to clipboard

Copied

I'm assuming it stays in memory until the GC comes and cleans it out?
I think so.

How long would that take?
That is up to the garbage collector.

Probably a setting in CF?
I don't know of any setting in CF to influence when the GC will operate on a particular object. In fact I suspect such a setting does not exist.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 21, 2008 Apr 21, 2008

Copy link to clipboard

Copied

I was testing a few things this Friday and ran out of threads, I couldn't add more. I went into the server monitoring component and noticed that I had a ton of threads running and several others queued. I'm pretty sure it was a collection of all the threads I had created during the afternoon testing my prototype.

Should I add a terminate call at the end to make sure they get disposed of properly?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 21, 2008 Apr 21, 2008

Copy link to clipboard

Copied

What do you mean when you say you couldn't add more? What was Coldfusion's response?

It is always a good thing to make sure threads come to a graceful end. Also, those that you want to continue should not be high consumers of memory. Otherwise Coldfusion might come to a standstill.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 21, 2008 Apr 21, 2008

Copy link to clipboard

Copied

My bad... I did a few more tests today and noticed the queued threads total decreasing, 10 threads a time. At some point, it reached zero, so they do get processed at some point. However, once my queued threads reached 0, I still had 104 threads running and it remained like that until I restarted the service in which it reset to 0.

I just want to know what to do in order to have threads do what they are supposed to and then stop using resources (memory, cpu, threads, ect...)

Is calling a terminate at the end of the thread make this possible or simply making the thread run its course?

My goal is to write a small daemon thread that limits the number of threads running. Once the max thread number drops, then the daemon thread starts another one from the queue. The client is there waiting until his specific thread is done (ajax refresh type thing).

Since the worker threads will have different timeout points (or there is no possible way to determine how long the thread can take), I can't use event gateways (at least I don't think so at the moment).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 21, 2008 Apr 21, 2008

Copy link to clipboard

Copied

I did a few more tests today and noticed the queued threads total decreasing, 10 threads a time. At some point, it reached zero, so they do get processed at some point. However, once my queued threads reached 0, I still had 104 threads running and it remained like that until I restarted the service in which it reset to 0.

Threads are the proverbial can of worms. Leave the lid open, and they're all over the place.

Is calling a terminate at the end of the thread make this possible or simply making the thread run its course?

The terminate action of the cfthread tag instructs Coldfusion to stop processing the thread.

My goal is to write a small daemon thread that limits the number of threads running.

I get the feeling that might be risky. I would leave that kind of control over to Coldfusion. See what you can do with the settings on the page Server Settings => Request Tuning in the Administrator.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 22, 2008 Apr 22, 2008

Copy link to clipboard

Copied

What I should have said was that I want to limit the amount of very specific threads that my own application launches - I'm on a corporate shared environment.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 22, 2008 Apr 22, 2008

Copy link to clipboard

Copied

I don't know how to place a global limit on threads without involving the Coldfusion Administrator. I wonder whether it's even possible. It involves some complexity. All requests involve threads, and there are thread groups, for example, web and jrun. In my opinion all you can, and should, do is make sure that your application's threads come to a graceful and timely end, and that they consume minimal memory.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 23, 2008 Apr 23, 2008

Copy link to clipboard

Copied

Not sure if this clears things up but all of this is related to the tag cfthreads, those are the ones I want to limit/control in my app.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 23, 2008 Apr 23, 2008

Copy link to clipboard

Copied

The only facility I know of in cfthread is to call the terminate action on a named thread.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 10, 2008 Oct 10, 2008

Copy link to clipboard

Copied

When I terminate a thread in this manner to kill runaway thread:

<cfloop list="#t#" index="i">
<cfif findNoCase('RUNNING', evaluate('#i#.status')) gt 0>
<cfsilent> <cfthread action="terminate" name="#i#" /> </cfsilent>
</cfif>
</cfloop>

Each thread that is terminated gets logged in the application log of the CF administrator.

How do I keep this from getting logged?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 10, 2008 Oct 10, 2008

Copy link to clipboard

Copied

> How do I keep this from getting logged?

Write your code so the threads finish gracefully, without you having to
kill them?

-- or --

If you have to kill these runaway threads... why is it a problem that their
death gets logged?

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 10, 2008 Oct 10, 2008

Copy link to clipboard

Copied

LATEST
>> How do I keep this from getting logged?

>Write your code so the threads finish gracefully, without you having to
>kill them?


The thread is very simple. Only a few lines of code and it finishes just fine. But, because of the nature of application, about a hundred threads are spawned and the garabage collector normally kills all of them by the time the join is completed. However, sometimes some of those threads hang around for no apparent reason. So, after the threading has been completed, then I would like to check to make sure they have been freed up so they are available for other requests.


-- or --

>If you have to kill these runaway threads... why is it a problem that their
>death gets logged?


Because killing a thread should not be considered an application error.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation