开发者

Using Quartz in an Asp.Net MVC environment using NHibernate Burrow

I have a web site running Burrow, and I'd like to use it for Quartz jobs as well.

The thing is that I want them to not share any state. The Quartz jobs is running in each own threads while the Mvc framework closes the Workspace at the end of every request. Ideally, mvc should have it's own session, and each job should have it's own session.

What a开发者_StackOverflow中文版re my possibilities here?

PS: I'm very new to Quartz, Burrow and MVC btw, so I'm probably missing some very essential knowledge :|


I tried a simple naive way that at least seem to work for now. Is there something fundamentally wrong I'm doing here? Will these variables be garbage collected when a thread exits?

public static class SessionManager
{
    [ThreadStatic]
    private static IDictionary<ISessionFactory, ISession> _sessions;

    public static ISession GetSession(Type type)
    {
        var burrow = new BurrowFramework();

        if (burrow.WorkSpaceIsReady)
        {
            return burrow.GetSession(type);
        }
        else
        {
            if (_sessions == null)
            {
                _sessions = new Dictionary<ISessionFactory, ISession>();
            }

            var factory = burrow.GetSessionFactory(type);
            if (!_sessions.ContainsKey(factory))
            {
                _sessions[factory] = null;
            }

            var session = _sessions[factory];
            if (session == null || !session.IsOpen)
            {
                session = _sessions[factory] = factory.OpenSession();
            }

            return session;
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜