Suggetions for Threads
hi,
i develop an web application in which i start threads for reading tables with status=N.
Right now what i do is that i have threads as an inner class of main class.
What i do is when user click start at that time i have an object of main class so i just call
mainclass.threadclass.start();
is above approach is better or i manage thread with different approach.
Threads just keep reading table.
Regards
[454 byte] By [
emmi@javaa] at [2007-11-27 6:54:52]

Yep, that's an unusual approach... The usual approach is to create independent Runnable classes... which can then be "fired up" on any thread you choose... but if it works, and it suits the overall design of your application then I don't see a problem with it... but I'm no swing guru, or 00 design guru for that matter.
Keith.
hi,
I didn't make independent runnable class because it using different variables from main class.
I see one problem sometimes i saw some threads are starting but when i stop by clicking stop it wont stop.
i think these are sme orphan threads,
how to manage them
regards
of course the servlet processing doesn't stop when you hit stop on the browser.
ALL that does is tell the browser to stop waiting for a respons, it doesn't tell the server anything.
HTTP is stateless, the client can do whatever it wants and the server couldn't care less. It will however log (if so configured) an error when it can't send the response to the client but not before it's done doing its thing.
hi,In-fact i create a button in my JSP page when i click it it just change the value of parameter which break while loop of thread.I have question what is the good idea to handle threads in web based applications. which also interact with databases.Regards
You need to keep it in mind that a web application can be in use by many users at the same time. I doubt you want them all sharing the process that your background thread is performing. So you need some way in which the web transaction that is supposed to abort the thread identifies which thread belongs to it.
Don't extend Thread, always use a Runnable if it's an inner class it will still have access to the fields of your main class.
You may want to put a reference to the thread in the Session object. Then a subsequent transaction can interrupt the thread. Otherwise you need to put some kind of identifier on the web page with the stop button, for example you could put the Thread objects into a hashmap using some arbitary but unique text identifier.