I'm using the standard Jira Rest Java Client (2.0.0-m2) to retrieve issue data. I have the following code to demonstrate the problem:-
final JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory(); final URI jiraServerUri = new URI("http://myjirainstance.com"); final JiraRestClient jrc = factory.createWithBasicHttpAuthentication(jiraServerUri, "username", "password"); final Issue issue = jrc.getIssueClient().getIssue("RP-579").get(); System.out.println(issue.getStatus().getName()); System.out.println("done");
This all works fine, but the java process does not complete and remains open (presumably a thread is left open somewhere). If I add System.exit(0) then everything is killed off and the process ends, so I presume something in the client is not being close off when it should be. Should I be closing something off here? What am I missing?
Community moderators have prevented the ability to post new answers.
Please upgrade to newer version. We've fixed that problem in m8 I believe by adding .close() method to JiraRestClient, which need to be called after you're done with JiraRestClient instance. This is because HttpClient used in implementation have to be closed, as it have it's own thread pool.
Thanks! I upgraded to version 2.0.0-m25 and it now works fine. As you mentioned, there is now a "close" method on the client which closes it off.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Aleksander,
Sorry to ask this within a question, but there seems to be a further problem when using the new close method implemented >= m8 that looks like a bug. As you work for Atlassian I hope you can comment:-
I tried a very simple bit of code to try and transition an issue (note I added the sleep() to highlight the problem:-
final String pkey = "JiraRef" final JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory(); final URI jiraServerUri = new URI("http://jiraurl.com"); final JiraRestClient jiraRestClient = factory.createWithBasicHttpAuthentication(jiraServerUri, "username", "password"); final IssueRestClient issueRestClient = jiraRestClient.getIssueClient(); final Issue issue = issueRestClient.getIssue(pkey).get(); final Iterator<Transition> ite = issueRestClient.getTransitions(issue).get().iterator(); TransitionInput moveTransition = null; while (ite.hasNext()) { Transition transition = ite.next(); if (transition.getName().equals(transition_name)) { moveTransition = new TransitionInput(transition.getId()); break; } } if (moveTransition == null) { throw new Exception("Could not find transition for jira issue " + pkey); } issueRestClient.transition(issue, moveTransition); System.out.println("Started Waiting"); Thread.sleep(10); System.out.println("Stopped Waiting"); jiraRestClient.close();
When executed, it triggers an exception (reduced stack trace due to char limit):-
Exception in thread "Thread-0" java.util.concurrent.RejectedExecutionException at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadP
If I increase the Thread.sleep to 4000 nano seconds, everything works fine without issue. It's almost as if it's closed before it's finished making the transition (maybe because of Async?). Looks like a bug?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I did not tested that but looking at the code you're missing claim invocation on .transition - as JRJC is now async you have to either claim request or wait using async methods on request to be finished (I don't have code open right now but look at the methods in Promise interface).
So just doing
issueRestClient.transition(issue, moveTransition).claim();
should solve your problem, as thread will wait until client complete the request.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Whoops, thanks for highlighting! Now it works! Need to get try and get myself into the habit of remembering this on V2 of the client.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.