Killing Parent thread can kill child thread

hi frnds
can u help me on thread
i want to know if i am kill my parent thread.can it automatically kill chhild thread also.
and i want to know is there any way in java to kill thread
plz reply

ajju29 wrote:
and i want to know is there any way in java to kill threadNo, not safely and not reliably. Since there's no way to "kill" a thread without its cooperation, the previous question is not relevant as well.
What you want to do is set some flag that your thread periodically checks and maybe send an signal and/or interrupt to tell the thread to check the flag earlier. The thread should then quit on its own.
Everything else is unfixably broken.

Similar Messages

  • Can a parent thread kill a child thread?

    I'm writing a multi-threaded application in which it is possible for one of the threads to go into an infinite loop. Is there any way for a parent thread to actually kill the child thread that has gone into the infinite loop? Of course the parent thread won't actually be able to discern whether or not the child thread is in an infinite loop. I would specify some time out value, and when it has been exceeded, then I would want to kill the child thread. Is this possible without setting any sort of flag that the child would read, because once it gets stuck inside an infinite loop, there will be no way to read the flag.

    Here's an example of a program that I wrote to simply ping a server. It works somewhat backwards from what you were looking for (the child interrupts the parent) but should provide some clue:
    import java.net.*;
    import java.io.*;
    import java.util.Date;
    public class ServerPing extends Thread {
      String [] args;
      public static void main(String[] args) throws Exception {
        ServerPing sp = new ServerPing(args);
        sp.start();
      ServerPing(String [] args) {
        this.args = args;
      public void run() {
        Pinger pinger = new Pinger(this);
        pinger.start();
        try {
          sleep(30000);
        catch (InterruptedException x) {
          System.exit(0); // this is ok. It means the pinger interrupted.
        System.out.println("TIMEOUT");
        System.exit(1);
    class Pinger extends Thread {
      Thread p = null;
      Pinger (Thread p) {
        this.p = p;
      public void run() {
        try {
          URL simpleURL = new URL("http://localhost:7001/ping.jsp");
          BufferedReader in = new BufferedReader(new InputStreamReader(simpleURL.openStream()));
          String inputLine;
          while ((inputLine = in.readLine()) != null)
          System.out.println(inputLine);
          in.close();
          p.interrupt();   // <<-- interrupt the parent
        catch (Exception x) {
          x.printStackTrace();
    }

  • Child and Parent Threads

    I have a parent thread class PThread which
    instantiates some child threads CThread in its run()
    method..
    Now Child threads need to give their status/information
    back to Parent thread periodically.
    Can I child thread callback any function of Parent
    thread

    Actually in my case, 1 parent Thread is running and it instantiates multiple child Threads (the number will be decided based on input from some file)....Now these Child Threads are doing some measurements...Each Child Thread is maintaining a bool variable
    "isActive"...If the measurement is not bein taken, it sets the isActive flag to false, otherwise true...(Different Child threads have their own "isActive" Status)...
    Now, there are Some other classes in System who are interested in knowing which Measurements are Active....(that means they want to know the status of Individual Child threads).....These classes are
    interacting with Parent class only....
    That's why I wanted individual Childs to update their current status
    periodically to Parent , so that when Parent is asked this information
    from Other classes, it can Consolidate and present the data....
    This was the only purpose, why I asked whether we can call from
    inside Child Thread, any functon of Parent Thread..
    What I understood from your comments that if Child Thread has access to Parent Thread's Object....(wich should be passed to it during new),
    it can callback Parent's functions.
    That should solve the purpose.....
    Regarding stopping of threads, Parent thread is itself gets information/interrupt from some other class to stop itself... when it
    gets the information, it will stops the Child threads too...I was thinking of calling some stop()
    function of individual child threads which will call their interrupt()..
    And at the end I will call the interrupt() of Parent class....
    I don't know much about usage of join(), so will have to study more
    about how can I do it better.
    Also one thing more:-
    Both Child and Parent Thread classes are extending Thread.
    They don't have to extend from any other class...I have to
    write specific functionality in run() function of parent and class.
    Should I change it to runnable....Why did you advised against
    extending threads

  • [Solved] Bash: killing child processes

    I decided to make a session manager that will kill all child processes before exiting, the only problem is that it doesn't kill them all.
    I tried using the same function, and using it in conjunction with
    yes >/dev/null & bash
    yes >/dev/null & bash
    yes >/dev/null & bash
    yes >/dev/null & bash
    running in a terminal, and it sent all of them the TERM signal.
    I'm out of ideas.
    Code is here.
    The relevant section is:
    # Kill child process of given parent
    # This uses PIDs not names
    # Also prints out a list of child pids that should be killed
    # FIXME: Clean this up a bit
    kill_child_processes()
    PARENT_ID=$1
    # Find child processes and put them in the form PID%seperator%COMMAND
    local CHILD_PROCESSES=$(ps o ppid,pid,command | \
    awk "{if (\$1 == $PARENT_ID) {print \$2,\"_\",\$3;}}" | \
    sed 's| _ |%seperator%|')
    # Do this for each child
    for child in $CHILD_PROCESSES; do
    # Extract the PID and COMMAND into separate variable from $child
    local child_pid=$(echo $child | sed 's|%seperator%.*||')
    local child_command=$(echo $child | sed 's|.*%seperator%||')
    # If the child command has child processes, recurse through it
    if [ "$(ps o ppid,pid,command | awk "{if (\$1 == $child_pid) {print \$2;}}")" != "" ]; then
    kill_child_processes $child_pid
    fi
    # If the command isn't part of a blacklist, send it the TERM signal
    if [ x$(for dont_kill_command in $DONT_TERM; do \
    [ x$dont_kill_command == x$child_command ] && echo "MATCH"; \
    done) == x"" ]; then
    kill $child_pid &
    # echo the PID so we can use it later
    echo $child_pid
    fi
    done
    Thanks.
    Last edited by some-guy94 (2010-01-13 22:48:39)

    gradgrind wrote:You might like to try pkill / pgrep with the -g option?
    Unfortunately that isn't what I'm looking for, I want this to work with multiple sessions(not that difficult), and also work with other apps on other tty's.
    Currently what it does is it runs ps o ppid,pid,command x which gives a nice table
    1234 5678 command1
    1234 5679 command2
    and if the ppid matches the session's pid, it's pid is saved, and (this part is looped) if it has child processes, then the function is run on the pid, afterward the pid is killed.
    It works when I separate the function from the rest of the script, but when it is in a session it fails to work properly.
    Last edited by some-guy94 (2010-01-05 23:11:57)

  • Killing child process, not just the shell

    Killing child process, not just the shell
    #241 - 07/11/03 11:30 AM
    Edit post Edit Reply to this post Reply Reply to this post Quote
    Hi,
    I am working on a system for automatically testing student submissions on an introductory course about unix scripting. The program works by running a test script on a student submission, using Runtime.getRuntime().exec(). The Process object has a limited life span of 10 seconds (by default), and if it is still running after these 10 seconds, Process.destroy() is used to kill it.
    A bug exists when one of the submissions being tested times out. When the destroy() method is used it leaves a child process running... since students can also run
    some tests from the file submission client, the number of hanging processes soon adds up as they test and test again to get it right before submission. Eventually this results in too many processes and the server keels over.
    Does anyone have any ideas on killing these hanging processes?

    Not much help, but I think this is a known bug ...
    http://developer.java.sun.com/developer/bugParade/bugs/4770092.html

  • Catching Exception in Parent Thread

    Hi Pros,
    I have a thread having try-catch block. Whatever exception I am catching into catch block should be thrown to be handled by Parent thread.
    Is there any way to do this.
    Thanks,
    Abhijit

    You can't literally throw to the parent thread per se, and the concept of doing so doesn't really make any sense. But using UncaughtExceptionHandler, you can give some control to the parent thread.
    package scratch;
    public class Uncaught {
      public static void main (String[] args) throws Exception {
        Thread t = new Thread(new MyRunnable());
        Thread.UncaughtExceptionHandler eh = new MyUEH ();
        t.setUncaughtExceptionHandler (eh);
        t.start();
      static class MyRunnable implements Runnable {
        @Override
        public void run () {
          System.out.println ("Thread name is: " + Thread.currentThread ().getName ());
          throw new RuntimeException("Can't catch me, I'm the gingerbread thread!");
      static class MyUEH implements Thread.UncaughtExceptionHandler {
        @Override
        public void uncaughtException (final Thread t, final Throwable e) {
          System.err.println ("The uncaught exception stack trace for Thread " + t.getName() + " is: ");
          e.printStackTrace ();
    }

  • Name of the Parent Thread.

    How can I know the name of the parent thread( not the threadgroup). If I create any theads in the main() function...these threqads have to be spawned by the main.Thread. How can I get the name of the Parent thread which has spawned my thread?
    Thank you.

    the 0th element of the ".getParent()" call on the current threads threadGroup?
    Doesn't seem to be a formal way, but you could create a system by extending the Thread class.

  • How can a child below 13 use a Creative Cloud ID with parental permission?

    How can a child below 13 use a Creative Cloud ID with parental permission?(I do not mean using parental account directly, if any other option is available)

    I suspect that the issue is that Adobe likely doesn't issue Adobe IDs to children under 13, because of COPPA.  Given the nature of Adobe's products, the potential legitimate userbase of under-13s is small, and the compliance costs could be very high.  Bear in mind that a kid under 13 can't legally sign up for a Facebook account, with or without parental permission, either, because FB doesn't want the liability for compliance if it knowingly signed up under-13-year-olds. 

  • SQL Server 2012 Management Studio:In the Database, how to print out or export the old 3 dbo Tables that were created manually and they have a relationship for 1 Parent table and 2 Child tables?How to handle this relationship in creating a new XML Schema?

    Hi all,
    Long time ago, I manually created a Database (APGriMMRP) and 3 Tables (dbo.Table_1_XYcoordinates, dbo.Table_2_Soil, and dbo.Table_3_Water) in my SQL Server 2012 Management Studio (SSMS2012). The dbo.Table_1_XYcoordinates has the following columns: file_id,
    Pt_ID, X, Y, Z, sample_id, Boring. The dbo.Table_2_Soil has the following columns: Boring, sample_date, sample_id, Unit, Arsenic, Chromium, Lead. The dbo.Table_3_Water has the following columns: Boring, sample_date, sample_id, Unit, Benzene, Ethylbenzene,
    Pyrene. The dbo.Table_1_XYcoordinates is a Parent Table. The dbo.Table_2_Soil and the dbo.Table_3_Water are 2 Child Tables. The sample_id is key link for the relationship between the Parent Table and the Child Tables.
    Problem #1) How can I print out or export these 3 dbo Tables?
    Problem #2) If I right-click on the dbo Table, I see "Start PowerShell" and click on it. I get the following error messages: Warning: Failed to load the 'SQLAS' extension: An exception occurred in SMO while trying to manage a service. 
    --> Failed to retrieve data for this request. --> Invalid class.  Warning: Could not obtain SQL Server Service information. An attemp to connect to WMI on 'NAB-WK-02657306' failed with the following error: An exception occurred in SMO while trying
    to manage a service. --> Failed to retrieve data for this request. --> Invalid class.  .... PS SQLSERVER:\SQL\NAB-WK-02657306\SQLEXPRESS\Databases\APGriMMRP\Table_1_XYcoordinates>   What causes this set of error messages? How can
    I get this problem fixed in my PC that is an end user of the Windows 7 LAN System? Note: I don't have the regular version of Microsoft Visual Studio 2012 in my PC. I just have the Microsoft 2012 Shell (Integrated) program in my PC.
    Problem #3: I plan to create an XML Schema Collection in the "APGriMMRP" database for the Parent Table and the Child Tables. How can I handle the relationship between the Parent Table and the Child Table in the XML Schema Collection?
    Problem #4: I plan to extract some results/data from the Parent Table and the Child Table by using XQuery. What kind of JOIN (Left or Right JOIN) should I use in the XQuerying?
    Please kindly help, answer my questions, and advise me how to resolve these 4 problems.
    Thanks in advance,
    Scott Chang    

    In the future, I would recommend you to post your questions one by one, and to the appropriate forum. Of your questions it is really only #3 that fits into this forum. (And that is the one I will not answer, because I have worked very little with XSD.)
    1) Not sure what you mean with "print" or "export", but when you right-click a database, you can select Tasks from the context menu and in this submenu you find "Export data".
    2) I don't know why you get that error, but any particular reason you want to run PowerShell?
    4) If you have tables, you query them with SQL, not XQuery. XQuery is when you query XML documents, but left and right joins are SQL things. There are no joins in XQuery.
    As for left/right join, notice that these two are equivalent:
    SELECT ...
    FROM   a LEFT JOIN b ON a.col = b.col
    SELECT ...
    FROM   b RIGHT JOIN a ON a.col = b.col
    But please never use RIGHT JOIN - it gives me a headache!
    There is nothing that says that you should use any of the other. In fact, if you are returning rows from parent and child, I would expect an inner join, unless you want to cater for parents without children.
    Here is an example where you can study the different join types and how they behave:
    CREATE TABLE apple (a int         NOT NULL PRIMARY KEY,
                        b varchar(23) NOT NULL)
    INSERT apple(a, b)
       VALUES(1, 'Granny Smith'),
             (2, 'Gloster'),
             (4, 'Ingrid-Marie'),
             (5, 'Milenga')
    CREATE TABLE orange(c int        NOT NULL PRIMARY KEY,
                        d varchar(23) NOT NULL)
    INSERT orange(c, d)
       VALUES(1, 'Agent'),
             (3, 'Netherlands'),
             (4, 'Revolution')
    SELECT a, b, c, d
    FROM   apple
    CROSS  JOIN orange
    SELECT a, b, c, d
    FROM   apple
    INNER  JOIN orange ON apple.a = orange.c
    SELECT a, b, c, d
    FROM   apple
    LEFT   OUTER JOIN orange ON apple.a = orange.c
    SELECT a, b, c, d
    FROM   apple
    RIGHT  OUTER JOIN orange ON apple.a = orange.c
    SELECT a, b, c, d
    FROM   apple
    FULL OUTER JOIN orange ON apple.a = orange.c
    go
    DROP TABLE apple, orange
    Erland Sommarskog, SQL Server MVP, [email protected]

  • As a grand parent, how can I put some apps on an ipod touch and then give it as a gift?

    As a grand parent, how can I put some apps on an ipod touch and then give it as a gift?

    Apps and many other purchases are tied to the iTunes Store account via which they were purchased. So if you buy the app, that app is tied to your iTunes Store account. Without that account information, the child could not update the app nor back it up.
    I'd also suggest giving the child an iTunes gift card or gift certificate along with the iPod. If the child is too young to have and manage his or her own iTunes Store account, then his or her parent could set up an iTunes Store account to purchase the apps. That could be done with that gift card and not need a credit card. You can also gift specific apps, though again that would require the child or a parent to open an iTunes Store account through which to redeem the gift. For more information on gift options, see:
    http://support.apple.com/kb/HT2736
    Regards.
    Message was edited by: Dave Sawyer

  • How to get the parent window in sub-child controller class in javafx?

    how to get the parent window in sub-child controller class in javafx?

    You can get the window in which a node is contained with
    Window window = node.getScene().getWindow();Depending when this is invoked, you might want to check the Scene is not null before calling getWindow().
    If the window is a stage that is owned by another window, you can get the "parent" or "owner" window with
    Window owner = null ;
    if (window instanceof Stage) {
      Stage stage = (Stage) window ;
      owner = stage.getOwner();
    }

  • Join  a Parent Table with 2 Child table based on a value

    Dear Guru's
    We have a Parent Table and 2 Child table . The Parent Table has a column like seqtype with only 2 possible values C and S . If the Value is C , then the details are available in Child 1 table and if the Value is S then the Details are in Child 2 table
    How can we query the Data from this type of arrangement ? I am little bit confused and hit a road block
    Will the following query will work ?
    Select
    from Parent P , Child C1, Child C2
    where P.seqtype = C1.Seqtype
    and P.seqtype = C2.Seqtype
    With Warm Regards
    ssr

    You didn't mention the column names in two child tables. Whether the columns are same in 2 tables of these are different.
    If the columns are same better to go and change your design to have only one child table. However if stiil business stops you having one table you can use UNION ALL (Assuming you want to fetch same column information from two child tables) like below:
    SELECT p.col1
          ,c1.col2
          ,c1.col3
          ,c1.col4
      FROM parent     p
          ,child      c1
    WHERE p.seqtype = c1.seqtype
    UNION ALL
    SELECT p.col1
          ,c2.col2
          ,c2.col3
          ,c2.col4
      FROM parent     p
          ,child      c2
    WHERE p.seqtype = c2.seqtype Regards
    Arun

  • Parent table of a child table

    I am using a child table 'CHILD_T' and in this table the column 'CHILD_FK' is the foreign key and it is pointing to some parent table. In my oracle editor I can see only synonyms but not actual tables. Is there any way to find out the parent table for this child table. Why I am asking this is because , I am getting below error while trying to execute the below script.
    Here I think my question is pretty simple but I would like to know how to find a parent table of a child table as I can see only synonyms instead actual tables.
    Script :
    INSERT INTO CHILD_T ( EM_ID, DFLT_COST_CNTR_TXT, ACCT_TYP_ID, DFLT_ORD_TYP_ID ) VALUES ('abcd', 'NA', '1', '1' );
    Error:
    SQL Error: ORA-02291: integrity constraint (AFM.USR_PROF_EM_ID) violated - parent key not found.
    Any one have any idea your help is well appreciated.

    select table_name  from user_constraints where constraint_name  in
        (select r_constraint_name from user_constraints  where constraint_name='YOUR_CONSTARINT_NAME');

  • Is it possible to put two different colors in tree parent node background and child nodes background?

    Is it possible to put two different colors in tree parent
    node background and child nodes background?
    Any help will be very helpful.
    Thanks

    Hi PanosE,
    Yes, you can set up another Standard Edition Server in child domain and then deploy pool pairing.
    You need to deploy a new Front End Pool for the new Standard Edition Server.
    A similar case for your reference.
    https://social.technet.microsoft.com/Forums/office/en-US/eca4299c-8edb-481e-b328-c7deba2a79ba/lync-2013-standard-edition-lync-fe-pools-in-multiple-domain-single-forest-senario?forum=lyncdeploy
    Best regards,
    Eric
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact [email protected]

  • Is it possible to call a function in a parent component from a child component in Flex 3?

    This is probably a very basic question but have been wondering this for a while.
    I need to call a function located in a parent component and make the call from its child component in Flex 3. Is there a way to access functions in a parent component from the child component? I know I can dispatch an event in the child and add a listener in the parent to call the function, but just wanted to know if could also directly call a parent function from a child (similar to how you can call a function in the main mxml file using Application.application). Thanks

    There are no performance issues, but it is ok if you are using the child component in only one class. Suppose if you want to use the same component as a child to some bunch of parents then i would do like the following
    public interface IParentImplementation{
         function callParentMethod();
    and the parent class should implement this 'IParentImplementation'
    usually like the following line
    public class parentClass extends Canvas implements IParentImplementation{
              public function callParentMethod():void{
         //code
    in the child  you should do something like this.
    (this.parent as IParentImplementation).callParentMethod();
    Here using the Interfaces, we re decoupling the parent and the child
    If this post answers your question or helps, please mark it as such.

Maybe you are looking for

  • 24" iMac refurb - kernal panic after apple logo

    I received a refurbished 24" C2D iMac on Friday and it seemed to be in perfect condition. Everything worked, and all of the updates were applied. Upon returning to the office on Monday, there was a kernal panic when awakening it. It also consistently

  • Urgent - Migrate data from Excel sheets

    Hello all.. I want to move data from excel sheets into oracle9i Database I have a bout 50 table with average of 5000 row per table How could I do it I will be so obligated if you could detail it for me Thanks in advance

  • Not all videos will import into iphoto...

    hi, i cannot get all my videos to import into iphoto 09. the process stops with an error "there was an error importing Photo". what is causing this and is there a workaround? please advise. thank you.

  • No sound with iTunes 7

    I, too, have NO sound at all now after upgrading to iTunes 7. Not just in iTunes - I can't listen to anything on my computer. From websites, CDs, nothing. What happened? Is there some setting that I have to change?

  • My phone has locked me out, but i am putting in the correct pasword every time?what do i do ?

    i have recently changed my pasword from a word, to the standard 4 diget pasword. my phone has decided that my pasword is incorect when i know for definate that it is correct! what do i do ?!