Click to See Complete Forum and Search --> : this thread = null


attilio
June 11th, 2006, 10:05 AM
hey! have a little thread reference question.

My thread is created by mainThread referenced by, mainThread.t[0]

In the thread I want to set it as null in order to terminate it? Or is their no point setting it to null?

At the moment i am refencing a termination function within the thread that kills all arrays and thread variables and sets the thread to null with the following code:

t[this.i] = null; is that how I should do it? or is it not neccessary at all?
if it is is there a local reference rather than having to null the thread via mainThread? ie, this = null

also as I have many threads all contacting each other via mainThread will this cause a problem as they are all going via mainThread should 2 threads call mainThread at the same time?

wildfrog
June 11th, 2006, 10:45 AM
My thread is created by mainThread referenced by, mainThread.t[0]

In the thread I want to set it as null in order to terminate it? Or is their no point setting it to null?
The thread won't stop just by removing the references to it. You should have some kind of condition that your thread evaluates, and when the condition is met the thread should terminate gracefully.

See The Life Cycle of a Thread (http://java.sun.com/docs/books/tutorial/essential/threads/lifecycle.html).

also as I have many threads all contacting each other via mainThread will this cause a problem as they are all going via mainThread should 2 threads call mainThread at the same time?Some methods are thread-safe, some are not. If you access a non-thread-safe method concurrently from multiple threads, you should implement synchronization.

See Synchronizing Threads (http://java.sun.com/docs/books/tutorial/essential/threads/multithreaded.html).

- petter

attilio
June 11th, 2006, 12:18 PM
ok thankyou very much, do i need to syncnorize all i/o operations inbound and outbound of the thread also? I have referenced output via a thread from other threads?

What is happening now, say the thread outputs some data, then another thread outputs data to the same thread too at the same time? do they just queue?
Will this happen on all array reading and writing too? or do i have to syncnorize it all?