I would appreciate if if someone could help me with this program. I have created a producer and consumer object as separate intities and have them communicating by one producing some text and the other consuming the text. I have read the items that I have been able to find in the saloon but thus far, they are of no help. Is there a way to stop a thread without using the stop class. ie. stop the producer then tell the consumer that the producer has finished and thus it should stop too? Currently, the producer produces the current date and time, while the consumer sleeps for a brief amount of time, then the producer sleeps for a moment and so it goes. I can get it to stop using the stop() but that has beendepricated and so I would prefer not doing so. I need to get this done ASAP, because my lab is due tomorrow. Any help would be appreciated. thanx ron
Simplest would be to add a pleaseStop() method that sets a boolean member variable askedToStop to true. Then, instead of while(true) use while (!askedToStop). More advanced would be to interrupt the consumer by calling interrupt() on its thread, and have the consumer check Thread.currentThread().isInterrupted() to tell it when to shut down.