The function of implementing database table data movement in the timer, Exception in thread "Timer-0" isexist java.lang.NullPointerException timer error.

Source: Internet
Author: User

1  Packagecom.shawnway.trade.marketdata.constants;2 Importjava.sql.SQLException;3 ImportJava.util.Calendar;4 Importjava.util.Date;5 ImportJava.util.Timer;6 ImportJava.util.TimerTask;7 8 ImportJavax.persistence.EntityManager;9 ImportJavax.persistence.PersistenceContext;Ten  One ImportOrg.slf4j.Logger; A Importorg.slf4j.LoggerFactory; - Importorg.springframework.beans.factory.annotation.Autowired; - Importorg.springframework.stereotype.Component; the Importorg.springframework.web.bind.annotation.RequestMapping; - ImportOrg.springframework.web.bind.annotation.RequestMethod; - ImportOrg.springframework.web.bind.annotation.ResponseBody; -  + ImportCom.shawnway.trade.marketdata.services.ChartService; -  + @Component A  Public classTimerconfig { at @Autowired -         PrivateChartservice Chartservice; - @PersistenceContext -         PrivateEntitymanager em; -          Publictimerconfig (Chartservice CT) {//key resolves null pointer error, -Chartservice=CT; in         } -       //timer.scheduleatfixedrate (timertask task,date firsttime,long period) to       //daily 24:00:00 to perform migration operations +      Public voidinit () { -Calendar Calendar =calendar.getinstance (); theCalendar.set (Calendar.hour_of_day, 15);//Control Time *Calendar.set (Calendar.minute, 3);//Control Points $Calendar.set (Calendar.second, 0);//Control secondsPanax Notoginseng       -Date time =Calendar.gettime ();  the       +Timer timer =NewTimer (); ATimer.scheduleatfixedrate (NewTimerTask () { the         +            Public voidrun () { -SYSTEM.OUT.PRINTLN ("Processor starts running"); $                $             Try { - movestablemes (); -}Catch(SQLException e) { the                 //TODO auto-generated Catch block - e.printstacktrace ();Wuyi             } the           } -}, time, 1000 * 60 * 60 * 24);//This setting will delay the execution of the daily fixed Wu     } -@RequestMapping (value = "/move/movestablemes", method =requestmethod.get) About @ResponseBody $      Public  voidMovestablemes ()throwssqlexception{ -         //first, determine if the storage table exists, and if it exists, transfer the data -         //If it does not exist, create the storage data table before transferring the data -         //The situation temporarily stores the table. (temporary tables are used to hold data for the current day.) ) ACalendar C =calendar.getinstance (); +         intYear=C.get (c.year); the         intMonth=c.get (C.month) +1; -         intToday =C.get (c.day_of_month); $String tbname= ""; the         if(month<=9)  theTbname= "Market_data_candlechart_" +integer.tostring (year) + "0" +integer.tostring (month);//the name of the database the         Else  theTbname= "Market_data_candlechart_" +integer.tostring (year) +integer.tostring (month);//the name of the database -String tempertb= "Market_data_candlechart";//table name where temporary information is stored inSystem.out.println ("performed to Isexist"); the         BooleanFlag=chartservice.isexist (Tbname);//determine if the corresponding database exists theSystem.out.println ("Isexist End"); About         if(flag) {//if it already exists, you can insert data from the temporary table directly into the corresponding table . theCHARTSERVICE.MOVEMESTOOLDTB (TBNAME,TEMPERTB);//move the data in the staging table to a table with the Tbname name.  the}Else{ theCHARTSERVICE.CREATETEMPERTB (Tbname);//If it does not exist, you need to create a table with the corresponding name first +CHARTSERVICE.MOVEMESTOOLDTB (TBNAME,TEMPERTB);//move the data in the staging table to a table with the Tbname name.  -         } the         //after the data has been transferred, the data of the temporary table is cleanedBayi CHARTSERVICE.DELETTEMPERTB (TEMPERTB); the     } the      -}

1  PackageCom.shawnway.trade.marketdata;2 3 4 5 Importjava.io.FileNotFoundException;6 7 ImportOrg.apache.catalina.Server;8 ImportOrg.apache.catalina.Service;9 ImportOrg.apache.catalina.connector.Connector;Ten ImportOrg.apache.catalina.valves.RemoteIpValve; One Importorg.springframework.beans.factory.annotation.Autowired; A Importorg.springframework.boot.SpringApplication; - Importorg.springframework.boot.autoconfigure.SpringBootApplication; - ImportOrg.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; the ImportOrg.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; - ImportOrg.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer; - Importorg.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; - ImportOrg.springframework.context.annotation.Bean; + ImportOrg.springframework.context.annotation.PropertySource; - Importorg.springframework.core.env.Environment; +  A ImportCom.shawnway.trade.marketdata.constants.SystemConfig; at ImportCom.shawnway.trade.marketdata.constants.TimerConfig; - ImportCom.shawnway.trade.marketdata.core.collect.MarketDataCollectHandler; - ImportCom.shawnway.trade.marketdata.core.ctp.CTPApiHandler; - ImportCom.shawnway.trade.marketdata.core.ctp.CTPGatewayProxy; - ImportCom.shawnway.trade.marketdata.core.ctp.CTPMarketDataHandler; - ImportCom.shawnway.trade.marketdata.core.ctp.CTPZeroMQHandler; in ImportCom.shawnway.trade.marketdata.core.es.EsMarketDataHandler; - ImportCom.shawnway.trade.marketdata.core.es.EsunnyApiHandler; to ImportCom.shawnway.trade.marketdata.core.es.EsunnyGatewayProxy; + ImportCom.shawnway.trade.marketdata.core.sp.SharppointApiHandler; - ImportCom.shawnway.trade.marketdata.core.sp.SharppointGatewayProxy; the ImportCom.shawnway.trade.marketdata.core.sp.SpMarketDataHandler; * ImportCom.shawnway.trade.marketdata.services.ChartService; $ ImportCom.shawnway.trade.marketdata.services.MapContainer;Panax Notoginseng  -@PropertySource ({"File:${config.dir}/config/web.properties" }) the @SpringBootApplication +  Public classApplicationlauncher { A @Autowired the     PrivateEnvironment env; + @Autowired -     PrivateChartservice Chartservice; $      $@Bean (name = {"Timerconfig"}, Initmethod = "Init") -      Publictimerconfig Timerconfig () { -System.out.println ("Timerconfig has begun to run ~"); the         return NewTimerconfig (Chartservice);//
Chartservice passed in to resolve null pointer errors
 -  } Wuyi  Public Static voidMain (string[] args)throwsException { theSystem.setproperty ("Config.dir", System.getproperty ("User.dir"));  - FinalString dir = system.getproperty ("Config.dir");  WuSystem.setproperty ("Logging.config", dir + "/config/logging.xml");  -Springapplication.run (Applicationlauncher.class, args);  About  }  $}

The function of implementing database table data movement in the timer, Exception in thread "Timer-0" isexist java.lang.NullPointerException timer error.

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.