Avoid restart your application

  Abstract: avoid restart your application 

  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width = "100%" border = "0" cellspacing = "0" cellpadding = " 0 "> <tr> <td width="284" height="86" align="center" valign="top"> </ td> <td width="400" valign="top"> 

  In the development and testing stage, a certain functional modules mistakes or functional requirements change, this time programmers would normally modify the source code, and then recompiled, and stop applications, re-starting the application.    It then revised in the function is correct, whether or not meet the demand.    Well, all in the development and testing stage, no problems have understandable.    But to the application Zhengshishangxian appeared in trouble.    Application will lead to the resumption system can not be used, or lead to the request of users, loss of response.    Some even shape the system requirements of this dynamic additions to the system, in the absence of your application added to prevent the re-launch strategy, usually can do is to take advantage of users 2:00 less time you restart the application or temporarily switch to backup systems. 
  If you have encountered a system will be inevitable, or encountered such a problem, and that in this article, several solutions can be used for your choice. 

  1: Before the start, not the preservation and processing of the request to the user's response.    Better way is to receive requests, send your response to the processing module and the modules separate application logic design.    If the current web server, can you re-deployment (redploy) at the request of users temporarily stored in queues, wait until after the successful deployment submitted to the processing logic modules.    Also, receive requests, the module is sent response to different applications.    And the application logic modules through the document (the sequence into a document request), including the exchange of data, so that the logic of your application after the restart, it can still continue to read request 

  </ Td> </ tr> </ table> 


  Second: If the function is purely to update data, then use dynamic allocation, avoid restart.    For example, a web system to provide reloadConfig interface, re-read from the configuration file in the data.    A java application, you can process your application in the detection launch a thread, testing whether the document was changed, if the change will automatically re-loading configuration.    The following examples: 
  Public ConfigChecker extends Thread 
  ( 
  SystemManager sm = null; / / System Manager 
  Long time; 
  Public ConfigChecker (SystemManager sm) throws ApplicationException 
  ( 
  This.sm = sm; 
  Time = getConfigFileTime ();// access configuration file final modified 
  ) 
  Pulblic void run () 
  ( 

  While (! Interrupted ()) 
  ( 
  Try 
  ( 
  Long newTime = getConfigFileTime ();// access configuration file final modified 
  If (newTime! = Time) 
  ( 
  Time = newTime; 
  / / Reloading configuration 
  Sm.reloadConfig (); 

  ) 
  Thread.sleep (1000 * 3) 
  ) 
  Catch (Exception ex) 
  ( 
  Return; 
  ) 

  ) 
  ) 

  Public long getConfigFileTime () throws ApplicationException 
  ( 
  Try 
  ( 
  File f = new File (sm.getConfigFile ());// access configuration file 
  Return f.lastModified () / / return profile of the modified final 
  ) 
  Catch (IOException ex) 
  ( 
  Throw new ApplicationException (ex.getMessage ()) 
  ) 

  ) 
  ) 


  This way for you to dynamic change is pure data, it requires the application of data you can not write died in the code, but through configuration files.    Through re-read from the configuration file in the data to restart 

  3: If the updated features include application logic, which is to change the class, then a little trouble, you need to understand the principles of ClassLoader.    Use your custom ClassLoader Load has been re-compiled class can be compared to restart application you like.    Below will be brief ClassLoader principle, and cited an example to illustrate how to avoid reopening applications 


  Virtual Machine to carry through Classloader category.    Bootstrap loader is responsible for the class load jdk (java. *, javax .*), the system class loader is bootstrap subclass for the load all chasspath designated variables.    ClassLoader will flow into Class B category, byte stream may ↑ Back 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Recommend Articles

Comments

Leave a Reply