Help with tracking thread name in AGI Server

Hello Everyone I’ve been looking for a way to track the thread name in AGI server which I gave during the thread’s initialization:

Here’s the code in details:

for(int i = 1; i <= 2; i++) /for example im creating 2 threads here for originate
{

    Map<String,String> destinationMap = new HashMap();

    if(i ==1)
     {
           destinationMap.put("numberToCall", "12345");   
     }
    else if(i == 2)
    {
           destinationMap.put("numberToCall", "678910");   
     }


    OriginateAction originateAction; 
    ManagerResponse originateResponse; 

   originateAction = new OriginateAction(); 
   originateAction.setChannel("Local/1239@from-internal-custom/n"); 
   originateAction.setContext("default"); 
   originateAction.setExten("7004"); 
   originateAction.setPriority(new Integer(1)); 
  originateAction.setTimeout(new Integer(30000));
  originateAction.setVariables(destinationMap);

  ManagerConnection something;

 ManagerConnectionFactory factory123 = new ManagerConnectionFactory( 
   "192.168.0.99", "admin", "admin"); 


   something = factory123.createManagerConnection();

   something.login(); 


   Thread t = new Thread(new HelloManager.AGIServerTask(something,originateAction));

   t.setName("Thread " + i);

    //CALCULATE START TIME
    t.start();

}

private static class AGIServerTask implements Runnable
{
private ManagerConnection managerConnection = null;
private OriginateAction originateAction = null;

    public AGIServerTask(ManagerConnection managerConnection, OriginateAction originateAction)
    {
        this.managerConnection = managerConnection;
        this.originateAction = originateAction;
    }
    
    public void run()
    {
        try
        {
          
                      
            managerResponse = managerConnection.sendAction(originateAction,90000);
           
            System.out.println("my name is " + Thread.currentThread().getName());
            //will println the "Thread i" which is exactly the name I assigned to my thread
            // If i record the end time here it is already late
        } 
        catch(IOException io)
        {
          
        }
        catch(TimeoutException te)
        {
           
        }
        
        
    }
}

and here are my dialplan:

exten => 1239,1,NoOp(number to call is = ${numberToCall})
exten => 1239,2,Agi(agi://192.168.0.216:3453/1239?numbertocall=${numberToCall})

exten => 1300,1,Hangup()
exten => 1300,2,Answer()
exten => 1300,3,Playback(thank-you-for-calling)
exten => 1300,4,AMD()
exten => 1300,5,Agi(agi://192.168.0.216:3453/1300?AMDStatus=${AMDSTATUS})

inside exten 1239 AGI server code I will issue:

System.out.println("thread name is " + Thread.currentThread().getName() );
// will println “Asterisk Daemon thread - Thread something” which is not what I want

exec(“Dial”,“SIP/CallOut/” + numberToCall + “@a2billing,60,G(from-internal-custom,1300,1)”);
//will transer the call to exten 1300 once someone answers

inside exten 1300 AGI server code I will issue:

 if(AMDStatus == human)
 { 
     //I WANT TO CALCULATE END TIME HERE
    //do something
    }

So basically what I am doing is initializing as many threads and originate action as the number of people that I have in my database. I will then call all of them and will do some action if the AMD algorithm detect human (instead of fax or answering machine) on the called party.

I will also need to calculate the time it takes from the point I initiate the originateAction until the called party answers and confirmed human (lets assume that it is point starttime to endtime) for each call . In order to do that I will need to assign a unique name in each thread and later match point endtime with the corresponding point starttime. However,because the Thread.currentThread().getName() information is gone once we enter the section in AGI server, I willl not be able to know which thread is which.

Any suggestion in solving this?

Thank you so much