Jfinal solution for long-cycle operation in Afterjfinalstart: Creating a new Thread

Source: Internet
Author: User

Many times, it is necessary to afterjfinalstart the method in the Jfinal, write some programs that need to run continuously, do some cyclic operation. However, in Afterjfinalstart, the execution time is too long, which causes the entire site to start to time out.

The solution is to create a new thread and start it in Afterjfinalstart:

1  PackageCom.thread;2 3 ImportCom.activeMQ.ActiveMQHelper;4 ImportCom.demo.testSpring.Animal;5 6 /**7 * Newly created thread for accepting messages and corresponding actions8  * @authorCzg9  *Ten  */ One  Public classWorkerextendsthread{ A      -      Public voidrun () { - String msg; theActivemqhelper activemqhelper=NewActivemqhelper ("Tcp://localhost:61616?wireformat.maxinactivityduration=0", 2000); -  -          while(true){ -Msg=activemqhelper.receivemessage ("Hello"); +             if(!msg.equals ("EOF") ) System.out.println (msg); -          +         } A     } at}
Thread Implementation
1 @Override 2      Public void Afterjfinalstart () {3         4         New Thread (new  com.thread.worker ()); 5         Workerthread.start (); 6     }
Thread Start

Jfinal solution for long-cycle operation in Afterjfinalstart: Creating a new Thread

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.