I have a work project where I am having multiple threads call a utility function I created that sends a post form to an internal API we have.
I use the callAPI
method here which is in a utility class, which is public, final and static :
public static int callAPI(String url, TaskListener listener, String operation, String id, String password, String sUser){
Client client = ClientBuilder.newClient();
Form form = new Form();
form.param("case", id);
form.param("user", sUser);
form.param("password", password);
listener.getLogger().println("*******************************************************");
listener.getLogger().println("Sending API Service Request");
Response response = client.target(url)
.path(operation)
.request(MediaType.APPLICATION_JSON)
.post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE));
}
I then have this run method in my Runnable class:
@Override
public void run(){
listener.getLogger().println("Thread Started.\n");
int runId = Utility.callAPI(wUrl, listener, operation, password, sUser);
listener.getLogger().println("call completed");
}
So what actually prints in Jenkins console output:
*******************************************************
Sending API Service Request
Thread Started.
This means I know my run()
method is being called and so my thread is starting. I know it can see my runAPI
method in the utility.
Now all I can gather is that this line:
Response response = client.target(url)
.path(operation)
.request(MediaType.APPLICATION_JSON)
.post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE));
sends a request and from there the thread exits before it finishes off the rest of the run()
method.
I've tried:
- putting a thread sleep loop
- putting the call in a while loop
It has been awhile since I've done any Java programming or threading. This is something very simple that I know I am forgetting.
ALSO I HAVE CHANGED A LOT OF MY CODE AND HAVE ONLY SHOWN THE CRITICAL PARTS BEING THIS IS PART OF A WORK PROJECT AND I DIDNT WANT TO TAKE CHANCES.