Question: I have a script that runs every 15 seconds and it creates a new thread every time. Now and then this thread gets stuck and blockes the synchronisation process of my program. Now i want to kill the process with a specific name if the thread is stuck for 20 loops. Here is my code:

```
public void actionPerformed(ActionEvent e) {

        Date dNow = new Date( );
        SimpleDateFormat ft = new SimpleDateFormat ("dd-MM-yyyy HH:mm:ss");
        System.out.println(ft.format(dNow));

        ThreadGroup currentGroup = Thread.currentThread().getThreadGroup();
        int noThreads = currentGroup.activeCount();
        Thread[] lstThreads = new Thread[noThreads];
        currentGroup.enumerate(lstThreads);
        boolean loopthreadfound = false;
        for (int i = 0; i < noThreads; i++){
        try{    
        if (lstThreads[i].getName() == "loopthread"){loopthreadfound = true;}           
        }catch(Exception e1){System.out.println(e1);}
        }

        if (loopthreadfound == false){
            loopthreadcounter = 0;
            //Starten in nieuwe thread
            Thread loopthread = new Thread() {

            public void run() {

                try {
                    checkonoffline();
                    checkDBupdates();
                    } catch (JSONException | SQLException | IOException e1) {
                    System.out.println(e1);
                    }
            }

            };

            loopthread.setName("loopthread");
            loopthread.start();

        }else{

            loopthreadcounter++;
            System.out.println("Loopthread already running...   counter: " + loopthreadcounter);        

            if (loopthreadcounter > 20){

             // HERE I WANT TO KILL THE THREAD "loopthread "

            }
        }

}

```

Answer: 
One option is to generate a CloudFormation ChangeSet using CDK and then deploy that ChangeSet later. To create the ChangeSet run `cdk deploy <StackName> --execute false`. This will synthesize the stack as well as upload templates and assets to S3. The ChangeSet can then be executed at anytime without CDK.
> 
> For this you execute cdk like cdk --app cdk.out deploy and it uses the already created cloud assembly in the specified folder instead of running synth.
> 
> 
> 

<https://github.com/aws/aws-cdk/issues/18790>