ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

What is parent and child thread in java?

user-image
تم إضافة السؤال من قبل L Bishwajit Sinha , Trainee developer , Nex-g exuberrant solutions Pvt Ltd
تاريخ النشر: 2013/06/27
ABDUL RAHIMAN ABDUL RAHIMAN M
من قبل ABDUL RAHIMAN ABDUL RAHIMAN M , Site Supervision, Estimation and CAD Draftsman , Alfalah Associates

I do a lot of java/j2ee work, but not much with the Thread class. I wrote a simple thread manager, which spawns two threads. Each of those threads then goes into infinite loops, with a Thread.sleep(3000) in the loop. I'd like to know if there's a way to kill one of the child threads (but leave the other one running) from the parent thread that spawned them. In Eclipse, I first tried to simply 'Terminate' one of the child threads, but alas, that terminates ALL the threads, children and the main parent. I've tried a child2.stop() in the parent thread (which has a reference to the Thread child2) but that crashed my Eclipse IDE pretty bad, so I'm not going to try that deprecated method again. I guess they MEANT it when they deprecated it I also tried child2.destroy(), but that threw an error....and didn't kill the child anyway. I tried child2.interrupt(), hoping that would force child2 to throw some kind of interrupt exception, but no luck there. In unix, it's quite simple to kill a given process. What's the trick to killing child threads in java? One caveat: child2 can have a deep call stack, i.e. lots of object.methods called pretty deeply, so it may be, say, off in a jdbc call at the time I want to kill it. Ben

المزيد من الأسئلة المماثلة