Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to stop all spammed threads?(please help)  RSS feed

 
Yaroslav Chinskiy
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Yaroslav Chinskiy
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!