# Code execution at the end of a parent node

**URL:** <https://forum.universal-robots.com/t/code-execution-at-the-end-of-a-parent-node/8494>\
**Category:** Java\
**Created:** [August 18, 2020, 10:51am UTC](https://forum.universal-robots.com/t/code-execution-at-the-end-of-a-parent-node/8494 "2020-08-18T10:51:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![othermartin](https://avatars.discourse-cdn.com/v4/letter/o/ebca7d/32.png) [@othermartin](https://forum.universal-robots.com/u/othermartin)\
**Post date:** [August 18, 2020, 10:51am UTC](https://forum.universal-robots.com/t/code-execution-at-the-end-of-a-parent-node/8494/1 "2020-08-18T10:51:32Z")

</div>

My URCap is configured as parent node and i start a new thread in the beginning of the execution of the node (contribution class / generateScript() method). Now i like to kill the thread, when the Robot program has finished the last child node, respectively it leaves the parent node.

Do i have to implement a second method similar then generateScript()?

Any Idea? Thanks!

edit:  
my code:

```
public class TestProgramNodeContribution implements ProgramNodeContribution{
...

    @Override
    public void generateScript(ScriptWriter writer){
        writer.defineThread("thread1");
            writer.whileTrue();
            writer.appendLine("textmsg(\"yo\")");
            writer.sleep(1.0);
        writer.end();
    writer.end();

    writer.runThread("thread1handle", "thread1()");
    }
...
}
```

---

<div class="post-metadata">

**Author:** ![m.birkholz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/m.birkholz/32/7084_2.png) [@m.birkholz](https://forum.universal-robots.com/u/m.birkholz)\
**Post date:** [August 18, 2020, 10:00pm UTC](https://forum.universal-robots.com/t/code-execution-at-the-end-of-a-parent-node/8494/2 "2020-08-18T22:00:29Z")

</div>

Yo,

I‘m not sure if i understood this right but i think you simply need to insert writer.writeChildren() after running your thread and then kill it on the last line

I would also recommend to define threads in your installation node otherwise you will have issues with multiple definitions of your thread with the same name

---

<div class="post-metadata">

**Author:** ![othermartin](https://avatars.discourse-cdn.com/v4/letter/o/ebca7d/32.png) [@othermartin](https://forum.universal-robots.com/u/othermartin)\
**Post date:** [August 19, 2020, 7:06am UTC](https://forum.universal-robots.com/t/code-execution-at-the-end-of-a-parent-node/8494/3 "2020-08-19T07:06:39Z")

</div>

Thanks i got it!  
I have seen writeChildren() already in some samples but i had problems to adapt it. Now it works 🙂
