Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Thread / Postback question

Status
Not open for further replies.

LucL

Programmer
Jan 23, 2006
117
US
Hi guys.

I've got two classes.

The first, is the primary (with void main, etc), it calls the secondary which is threaded to do something, waits for an available thread, then launches another one.

at any time there should be 10 threads running. the main function doesn't care about anything about the threaded class except whether or not the max_threads limit was reached. so, the main class will launch 10 threads, and just wait until 1 dies and launch another one, always keeping 10 threads running, but not caring about the result of the thread.

currently, when a thread finishes executing, it updates the thread count (active_threads int) on the main class. (ex: when it starts in run() it increments it and when it finishes in run() it decrements it) so that the main module knows how many threads are running.

here is the change need to make, currently i reference directly to the parent module like WS.active_threads--;
but what if I wanted to make the threaded module usable in other parent modules that may not be called WS but something else.

I tried with super.active_threads--; and then created a function on the parent thread to do it too super.dec_threads(); but it doesn't work (java error). Assuming that there will always be a active_threads integer on the parent thread, but the parent thread's name is not always known, is there any way to increment it?

Additionally, is there a way to perform a call on like a postback function, say i want my thread to execute a function on the parent thread when it's done?

Thanks!
Luc

 
btw, the error java is returning is "method increment_thread is undefined for type Thread)

my threaded class is declared like:

public class threadedClass extends Thread

I realize it extends to the Thread class, but still wonderig if there is a way to access the thread that originally initiated it.
 
I guess the easiest way is to just create a threadhandler class that keeps track of the active and max threads and can be added to any project along with anything that uses threads.

brain freeze. case closed. sorry, it's late.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top