• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

How to stop all spammed threads?(please help)

 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
First, you drop a couch from the plane, THEN you surf it. Here, take this tiny ad with you:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic