aspose file tools
The moose likes Threads and Synchronization and the fly likes How to stop all spammed threads?(please help) Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "How to stop all spammed threads?(please help)" Watch "How to stop all spammed threads?(please help)" New topic
Author

How to stop all spammed threads?(please help)

Yaroslav Chinskiy
Ranch Hand

Joined: Jan 09, 2001
Posts: 147
Hi,
I have a server that creates new thread per client.
public void run()
{
while(true)
{
try
{
s = server.accept();
QueueWriterThread qwt = new QueueWriterThread(s,records);
qwt.setDaemon(false);
qwt.start();
}catch (IOException ioe)
{
System.err.println(dfltErrorMsg + " " + ioe.getMessage());
}
}
once I start new thread I do not keep reference to it.
If server was stopped or killed by a user how do I make all spammed threads to stop?
I have static boolean STOP in all of them, but how do I change its value upon termination of the server?
Thanks, Yarik.
Tanveer Rameez
Ranch Hand

Joined: Dec 11, 2000
Posts: 158
hi
I am not getting your program very much.however from what I could understand...
Initially set STOP=false; in your constructor of the server.
The server may halt due to several reason.if there is an
exception oin the catch block you can set STOP=true;
}catch(exception e) {STOP=false;}
in the run method have the loop condition as
while(!STOP)
{
}
maybe this will help
regards
Tanveer

Author of JPhotoBrush Pro (www.jphotobrushpro.com)
Yaroslav Chinskiy
Ranch Hand

Joined: Jan 09, 2001
Posts: 147
Hi,
The method I posted is the run() from my server thread.
Per connection I create new QueueWriter which writes clients requests to a que. In the constructer of the QueueWriter I have public static boolean STOP = false, and in the run() i have
while(!STOP)
{
}
Therefore i can stop all instances.
I have other classes defined in the same way.
But how do I catch the moment when the servers thread is killed or stopped?
would finally or finalize work?
That is the main question.
Thank you for help.
Yarik.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How to stop all spammed threads?(please help)
 
Similar Threads
Terminating the server
Stopping RMI programatically
One thread as a scheduler on webserver
Thread Stops
Thread stuck problems - StuckThreadMaxTime exceeded