chanxianzhong / mybatisnet

Automatically exported from code.google.com/p/mybatisnet
0 stars 0 forks source link

使用IBatisNet开发一个Web应用程序,其实启动了多线程来自动执行任务处理,每10分钟处理一次,但出现了如下问题 #38

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
在Global.asax中初始化DaoManager
C# code
protected void Application_start(...){
   //初始化DaoManager
   WZW.IBatisNet.SqlMap.DaoConfig.GetInstance().InitBaseDaoManager();

   //记录系统启动日志
   Biz.SysLogBiz.GetInstance().AddLog("", Const.SYS_LOG_LOG_TYPE_SYSTEM_START, "系统启动成功!");

   Biz.AutoRunBiz.GetInstance();

}

自动处理程序如下:

C# code
public class AutoRunBiz
    {
        private static AutoRunBiz instance = null;

        public static AutoRunBiz GetInstance()
        {
            if (instance == null)
            {
                instance = new AutoRunBiz();
            }
            return instance;
        }

        public AutoRunBiz()
        {
            //定时运行
            Thread th = new Thread(new ThreadStart(this.Run));
            th.Start();
        }

        private void Run()
        {
            while (true)
            {
                Biz.MakePageBiz.GetInstance().MakeIndex();

                //每10分钟执行一次
                Thread.Sleep(600000);
            }
        }
    }

发现系统日志有如下问题:

系统启动 系统启动成功! 2009-10-26 19:40:19   
系统启动 系统启动成功! 2009-10-26 19:29:56   
系统启动 系统启动成功! 2009-10-26 19:19:47   

即每10分钟会初始化一次DaoManager

说明Global.asax中的Application_start每10分钟执行了一次,如果不��
�自动任务处理,则只会执行一次Application_start,

请高手帮忙?

Original issue reported on code.google.com by wanghui...@gmail.com on 2 Feb 2012 at 1:05