Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6725875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:51:33+00:00 2026-05-26T09:51:33+00:00

I am trying to run a long-running task (without blocking the HTTP request execution

  • 0

I am trying to run a long-running task (without blocking the HTTP request execution pool) using the Asynchronous Jobs in Play.
Jobs in Play are fully managed by the framework so Play will take care of the database connections and transactions. This means that a job runs as a plain invocation within a single transaction. This is great for most use-cases but what if you need to commit some data before the job finishes?

Well, according to Guillaume Bort, one option would be

to split your process into several small jobs

He gives the following example:

@On("0 0 12 * * ?") 
public class UpdateCounters extends Job { 
   public void doJob() { 
       List<Employee> empList = Employee.find("long and boring SQL :)").fetch(); 
       for(Employee emp : empList) { 
           new UpdateEmployeeJob(emp).now().get(); 
       } 
   } 
}

This is cool… Each new job will have it’s own transaction so when this new job finishes, it commits that data. Clean and simple!
But what if you don’t want to do this asynchronous? Say you need to wait until the data is committed before you continue with the initial job?

Normally, you would retrieve the Promise from the new Job and call await(jobPromise) but this will not work in a Job (await is only available when extending Controller and is not implemented on Job)…

So what would be the best way to pause the initial job until the new smaller job completes?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:51:34+00:00Added an answer on May 26, 2026 at 9:51 am

    After looking into different ways of finding out if a Job was done (without using a database), I noticed that a Play Promise implements the Future interface and thus has the isDone() operation which can be used this to check if the task completed.

    Even better, the Future interface also defines a get() method which

    waits if necessary for the computation to complete, and then retrieves
    its result.

    So pausing the initial job until the new smaller job completes, can be achieved by calling get() on the Promise, returned when calling now() on the smaller job (as indeed done in Guillaume’s example)

    Thanks!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently trying to use a .net Task to run a long method.
I wish to run a long-running script in the background upon receiving a request.
When trying to run an Eclipse Dynamic Web Project under a Tomcat setup using
I am new to Windows Workflow and trying to write a Long Running process.
I am trying to speed up a long running query that I have (takes
I have taken the task of trying to get an older program to run
I am trying to run this query on http://dbpedia.org/sparql but I get an error
I'm trying to gauge the CPU utilization level during a long-running process. I suspect
I have a long-running SP (it can run for up to several minutes) that
What I'm trying to accomplish: I want to call a long running business logic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.