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