Why doesn't complete flag get set unless you call GearmanJob.get method?

Asked by Dragan Vujovic on 2013-03-05

I am using the following code snippet:

Future<GearmanJobResult> result = client.submit(job);
while( !result.isDone() ) {
   log.info("Not Done");
   Thread.sleep(2000);
}

GearmanJobResult jobResult = result.get();

The isComplete flag never gets set unless you call the get method, so this code never ends.
If a remove the while loop everything is OK.
I would like to use the isDone method as a polling method so I can go through a list of Future objects,
and see if they are completed.

What is the right way to handle multiple Future<GJR> objects? I tried to use multithreading with thread pools handling the future objects but that had problems whith jobs not completing. Is GearmanClient thread safe? Should I instead use GearmanClient/Connection pools?

Thanks in advance

Question information

Language:
English Edit question
Status:
Solved
For:
Gearman Java Edit question
Assignee:
No assignee Edit question
Solved by:
Dragan Vujovic
Solved:
2013-03-06
Last query:
2013-03-06
Last reply:
2013-03-06
Eric Lambert (elambert) said : #1

Hi:

Yeah, just calling isDone() does not drive client IO with the server and as such the state of the Job will not be updated. Although there is no reason why it should not drive IO if the job is not done. I will file a bug to that effect.

In regards to threading, the current expectation is that the GearmanClient and the GearmanJob are not shared across threads.

As for how to handle multiple Future<GJR>s. First that I should point out that driving client IO (either by submitting jobs are calling get() on the Job) has the ability to up-date the state of multiple Future<GJR>s if new data is available for them (but i suspect that is not what you are asking). Ultimately, the thread which submitted the task which generates the future is expected to at some point to perform a get() to retrieve the result.

Let me know if this is not clear or you have any further questions.

Eroc

On Mar 5, 2013, at 3:45 AM, Dragan Vujovic wrote:

> New question #223439 on Gearman Java:
> https://answers.launchpad.net/gearman-java/+question/223439
>
> I am using the following code snippet:
>
> Future<GearmanJobResult> result = client.submit(job);
> while( !result.isDone() ) {
> log.info("Not Done");
> Thread.sleep(2000);
> }
>
> GearmanJobResult jobResult = result.get();
>
> The isComplete flag never gets set unless you call the get method, so this code never ends.
> If a remove the while loop everything is OK.
> I would like to use the isDone method as a polling method so I can go through a list of Future objects,
> and see if they are completed.
>
> What is the right way to handle multiple Future<GJR> objects? I tried to use multithreading with thread pools handling the future objects but that had problems whith jobs not completing. Is GearmanClient thread safe? Should I instead use GearmanClient/Connection pools?
>
> Thanks in advance
>
> --
> You received this question notification because you are an answer
> contact for Gearman Java.

Very clear,
thank you very much for the quick response.