JSP programming progress bar design example (2)

Source: Internet
Author: User

If the task has been started, the isStarted () method returns true:


Public synchronized boolean isStarted (){
Return started;
}
 


If the task has been completed, the isCompleted () method returns true:


Public synchronized boolean isCompleted (){
Return counter = 100;
}
 


If the task is running, the isRunning () method returns true:


Public synchronized boolean isRunning (){
Return running;
}



The SetRunning () method is called by start. jsp or stop. jsp. When the running parameter is true. The SetRunning () method also marks the task as "started ". Calling setRunning (false) indicates that the run () method is required to stop execution.


Public synchronized void setRunning (boolean running ){
This. running = running;
If (running)
Started = true;
}
 
After the task is completed, call the getResult () method to return the calculation result. If the task has not been completed, it returns null:


Public synchronized Object getResult (){
If (isCompleted ())
Return new Integer (sum );
Else
Return null;
}
 
When running is marked as true and completed is marked as false, the run () method calls work (). In practical applications, the run () method may need to execute complicated SQL queries, parse large XML documents, or call the EJB method that consumes a lot of CPU time. Note that "heavy tasks" may be executed on remote servers. The JSP page of the report result has two options: Wait for the task to end, or use a progress bar.


Public void run (){
Try {
SetRunning (true );
While (isRunning ()&&! IsCompleted ())
Work ();
} Finally {
SetRunning (false );
}
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.