I'm testing an AJAX application, and I need to test my loading/wait screens. I'd like to make the application take a longer time to respond to an AJAX request. The following code works okay, but is rather inelegant. Perhaps a thread or a timer?

    int i = 0
    double j

    for (i = 0; i < 1000000; i++) {
        j = Math.sin(j);
    } 
有帮助吗?

解决方案

You could just cause the thread to sleep with Thread.sleep(1000); but this would stop the entire back end application (if it was single threaded), so it would work if your waiting screen was client side javascript, not if it was fired from the server side.

其他提示

David is right. But if it's Groovy, you can shorten it to: sleep(1000)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top