JAVA¶¨Ê±Ö´ÐÐÈÎÎñ
Tomcat ϵĶ¨Ê±ÈÎÎñ
SysContextListener.java
package axtic.servlet;
import java.util.Timer;//¶¨Ê±Æ÷Àà
import axtic.bean.exportHistoryBean;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class SysContextListener implements ServletContextListener
{
private Timer timer = null;
public void contextInitialized(ServletContextEvent event)
{//ÔÚÕâÀï³õʼ»¯¼àÌýÆ÷£¬ÔÚtomcatÆô¶¯µÄʱºò¼àÌýÆ÷Æô¶¯£¬¿ÉÒÔÔÚÕâÀïʵÏÖ¶¨Ê±Æ÷¹¦ÄÜ
timer = new Timer(true);
event.getServletContext().log("¶¨Ê±Æ÷ÒÑÆô¶¯");//Ìí¼ÓÈÕÖ¾£¬¿ÉÔÚtomcatÈÕÖ¾Öв鿴µ½
timer.schedule(new exportHistoryBean(event.getServletContext()),0,5*1000);//µ÷ÓÃexportHistoryBean£¬0±íʾÈÎÎñÎÞÑÓ³Ù£¬5*1000±íʾÿ¸ô5ÃëÖ´ÐÐÈÎÎñ£¬60*60*1000±íʾһ¸öСʱ¡£
event.getServletContext().log("ÒѾÌí¼ÓÈÎÎñ");
}
public void contextDestroyed(ServletContextEvent event)
{//ÔÚÕâÀï¹Ø±Õ¼àÌýÆ÷£¬ËùÒÔÔÚÕâÀïÏú»Ù¶¨Ê±Æ÷¡£
timer.cancel();
event.getServletContext().log("¶¨Ê±Æ÷Ïú»Ù");
}
}
½ÓÏÂÀ´¿ÉÒÔ±àд×Ô¼ºµÄ¹¦ÄÜÀ࣬´ËÀàÒ»¶¨Òªextends¶¨Ê±Æ÷ÀàÖÐTimerTask
exportHistoryBean.java
package axtic.bean;
import java.util.Calendar;
import java.util.TimerTask;
import javax.servlet.ServletContext;
public class exportHistoryBean extends TimerTask
{
private static final int C_SCHEDULE_HOUR = 0;
private static boolean isRunning = false;
private ServletContext context = null;
public exportHistoryBean(ServletContext context)
{
this.context = context;
}
public void run()
{
Calendar c = Calendar.getInstance();
if(!isRunning)
{
if(C_SCHEDULE_HOUR == c.get(Calendar.HOUR_OF_DAY))
{
isRunning = true;
context.log("¿ªÊ¼Ö´ÐÐÖ¸¶¨ÈÎÎñ");
//-------------------¿ªÊ¼±£´æµ±ÈÕÀúÊ·¼Ç¼
//ÔÚÕâÀï±àд×Ô¼ºµÄ¹¦ÄÜ£¬Àý£º
//File file = new File("temp");
//file.mkdir();
//Æô¶¯tomcat£¬¿ÉÒÔ·¢ÏÖÔÚtomcat¸ùĿ¼Ï£¬»á×Ô¶¯´´½¨tempÎļþ¼Ð
//-------------------½áÊø
isRunning = false;
context.log("Ö¸¶¨ÈÎÎñÖ´ÐнáÊø");
}
else
{
context.log("ÉÏÒ»´ÎÈÎÎñÖ´Ðл¹Î´½áÊø");
}
}
}
}
ServletÕìÌýÆ÷½áºÏJava¶¨Ê±Æ÷ʵÏÖÈÎÎñ¼Æ»®µ÷¶
Ïà¹ØÎĵµ£º
Javaѧϰ´ÓÈëÃŵ½¾«Í¨
Ò»¡¢ JDK (Java Development Kit)
JDKÊÇÕû¸öJavaµÄºËÐÄ£¬°üÀ¨ÁËJavaÔËÐл·¾³£¨Java Runtime Envirnment£©£¬Ò»¶ÑJava¹¤¾ßºÍJava»ù´¡µÄÀà¿â(rt.jar)¡£²»ÂÛʲôJavaÓ¦Ó÷þÎñÆ÷ʵÖʶ¼ÊÇÄÚÖÃÁËij¸ö°æ±¾µÄJDK¡£Òò´ËÕÆÎÕJDKÊÇѧºÃJavaµÄµÚÒ»²½¡£×îÖ÷Á÷µÄJ ......
Reflection ÊÇJava±»ÊÓΪ¶¯Ì¬£¨»ò×¼¶¯Ì¬£©ÓïÑÔµÄÒ»¸ö¹Ø¼üÐÔÖÊ¡£Õâ¸ö»úÖÆÔÊÐí³ÌÐòÔÚÔËÐÐʱ͸¹ýReflection APIsÈ¡µÃÈκÎÒ»¸öÒÑÖªÃû³ÆµÄclass
µÄÄÚ²¿ÐÅÏ¢£¬°üÀ¨Æämodifiers£¨ÖîÈçpublic, static µÈµÈ£©¡¢superclass£¨ÀýÈçObject£©¡¢ÊµÏÖÖ®interfaces£¨ÀýÈçCloneable£©£¬Ò²°üÀ¨fields
ºÍmethodsµÄËùÓÐÐÅÏ ......
(1) transient:
Èç¹ûÓÃtransientÉùÃ÷Ò»¸öʵÀý±äÁ¿£¬µ±¶ÔÏó´æ´¢Ê±£¬ËüµÄÖµ²»ÐèҪά³Ö¡£ÀýÈ磺
class T
{
transient int a; //²»ÐèҪά³Ö
int b; //ÐèҪά³Ö
} //ÕâÀÈç¹ûTÀàµÄÒ»¸ö¶ÔÏóдÈëÒ»¸ö³Ö¾ÃµÄ´æ´¢ÇøÓò£¬aµ ......
ʹÓÃJ2SEAPI¶ÁÈ¡PropertiesÎļþµÄÁùÖÖ·½·¨
¡¡¡¡1¡£Ê¹ÓÃjava.util.PropertiesÀàµÄload()·½·¨Ê¾Àý£ºInputStream in=lnew BufferedInputStream(new FileInputStream(name));
properties p=newProperties(); p.load(in);
¡¡¡¡2¡£Ê¹ÓÃjava.util.ResourceBundleÀàµÄgetBundle()·½·¨Ê¾Àý£ºResourceBundle rb=ResourceBu ......