troubleshooting Question

Facing a problem while killing thread from java [JDK 1.6, JDK1.4]

Avatar of Yogeshup
Yogeshup asked on
17 Comments1 Solution1308 ViewsLast Modified:
Hi All,
I am facing a problem while killing thread from java [JDK 1.6, JDK1.4] running on windows. Here is my flow, I have three class;
Server Class :- Listens request broadcasted by source system,
Parent Class :- Holds the logic for creating thread class.
Child Class :- Holds the logic doing some  stuff related to business logic involves db operations[Eg.Proc execution].
I have a created a listener in java which will act as a server and will keeps on listening the request broadcasted. After getting the request it creates the object of parent class. Parent class creates the thread [child class object] which does some operation. Parent class is basically used for terminating thread [child class object] after specified timeout period. In parent class, after completion of specified time it interrupts the created thread by using .interrupt() method. But since this is just the Boolean flag it shows me correct flag if check thread status by using .isInterrupted() but in real scenario it doesnt stops the execution. I cached the interrupted thread as follows
catch (InterruptedException  iex){
It doesnt seems to work. I know that there is a limitation with threads in java but I tried lots of alternatives like,
1. I used .isInterrupted() method and by using system.exit() I terminated the thread but it shut downs my server class execution also which should not.
2. Thread terminates only after completion of its run method hence I tried to maintain the variable which will hold the Boolean value and in while block I checked it every time.
    public class Child extends Thread {
    public Child() {
        // put constructor stuff here!
    public void run () {
        //do something
        if (isStopped) return;
 Since this could not work in my case because in run method hold some business logic related to database hence it keeps on executing and keeps holding all it's locks and its references.
Any suggestions are highly appreciable
Thanks in advance.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 17 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 17 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros