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 9199185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:28:28+00:00 2026-06-17T22:28:28+00:00

The following awaits forever, I think. How do I specify a timeout? await(new Job<Long>()

  • 0

The following awaits forever, I think. How do I specify a timeout?

await(new Job<Long>() {
    @Override
    public Long doJobWithResult() throws Exception {
        ...
    }
}.now());
  • 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-06-17T22:28:30+00:00Added an answer on June 17, 2026 at 10:28 pm

    Implementing a timeout which kills a thread is actually a pretty difficult thing to do generically since you’d need to use Thread.stop() or something else horrid like that which might not clean up when it dies. The nicer way to do it is have the timeout set a flag in your long job that makes it stop processing and return sooner. Or alternatively, you let the long job continue and just render a response on the timeout.

    Here is a testcase that does what you want:

    https://github.com/playframework/play/blob/1.3.x/samples-and-tests/just-test-cases/app/controllers/WithContinuations.java#L73

    public static void waitWithTimeout() {
            Promise<String> task1 = new jobs.DoSomething(100).now();
            Promise<String> task2 = new jobs.DoSomething(2000).now();
            Either<List<String>,Timeout> r = await(Promise.waitEither(Promise.waitAll(task1, task2), Timeout(300)));
    
            for(Timeout t : r._2) {
    
                StringBuilder result = new StringBuilder();
    
                if(task1.isDone()) {
                    result.append(" + Task1 -> " + task1.getOrNull());
                }
    
                if(task2.isDone()) {
                    result.append(" + Task2 -> " + task2.getOrNull());
                }
    
                renderText("Timeout! Partial result is " + result);
            }
    
            renderText("Fail!");
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code: public Task SomeAsyncMethod() { var tcs = new TaskCompletionSource(); ...
Given the following method: public async Task<MyObject> DoSomethingAsync() { // do some work await
Still learning about async-await. I bumped into examples similar to following: public async Task
Please consider the following code public static async Task<int> Answer() { await Task.Delay(1000); return
Given the following ASP.NET MVC 4 controller action: public async Task<ActionResult> FooAsync() { using
i have the following code: public partial class MainWindow : Window { public MainWindow()
Assume the following synchronous code: try { Foo(); Bar(); Fubar(); Console.WriteLine(All done); } catch(Exception
What is the correct way to cancel the following? var tcpListener = new TcpListener(connection);
I need to know how to convert the following to VB.net for an Async/Await
The following code throws error at statement : Result res = (Result)stdserialize.ReadObject(ms); And the

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.