addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1launch-new-window--smalllight-bulblinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

Re: [ljc] Pausing execution in a web app

From: Alex A.
Sent on: Wednesday, July 3, 2013 12:52 PM
On 3 July[masked]:45, Jon Hatfield <[address removed]> wrote:
> I just had to pause execution for 5 seconds in an EJB, running on JBoss. Here are the various solutions I thought of, in order of what I think is best to worst:
> 1. Start a cached thread pool using the servlet context listener (to disassociate the HTTP request threads with creating new threads - cached in case graceful shutdown of threads fails) and tap into it to schedule a delayed action.
> 2. Create a polling service to trigger the process when appropriate.
> 3. Compare to <current time in millis + 5000ms> in a loop, which is pretty intensive.
> 4. Use Thread.sleep, which you should never really do in a web app.
> I temporarily went with 3, but only for a UAT environment, as no time for 1 or 2... could anyone with more web-based multi-threading advise, as I will need a better solution, especially for production?
> Thanks and regards,
> Jon

Hi!  Interesting problem.  Why is (3) considered better than (4)?
Should I understand the specific dangers of using Thread.sleep() in
web apps?

Our Sponsors

  • Our Blog

    Read the latest news from the LJC

  • RecWorks Ltd

    Fixing Tech Recruitment using the Power of Community

  • jClarity

    Java/JVM Performance Analysis Tools & mentoring for Java related matters

  • LJC Aggrity

    Our LJC Aggrity site contains blog posts from our members

  • LJC Book Club

    Our Book club with book reviews from our members

  • Devoxx UK

    Java Community Conference in collaboration with the LJC, 8-10th June 16

  • SkillsMatter

    "Host, help organise, promote, film many of our meetings."

  • IBM

    Build Enterprise-grade apps at start-up speed.

  • New Relic

    New Relic makes sense of billions of metrics a day in real time.

  • Hazelcast

    Hazelcast is the leader in operating in-memory computing.

  • Java.Net

    We are an official Java User Group recognised by Oracle's JUG program

  • JRebel

    Free 3 month J-Rebel license.

  • O'Reilly

    40% discount on printed books and 50% on e-books.

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy