【问题标题】:grails service with quartz使用石英的 grails 服务
【发布时间】:2012-11-22 12:33:51
【问题描述】:

我在 Grails 中编写了一个应用程序,但我在使用石英时遇到了一些问题。 我想从数据库中获取用户,然后再获取他的服务器。 如果有任何服务器我想检查每个服务器上的 PING 命令,但我收到这样的消息:

" [quartzScheduler_Worker-1] 错误 listeners.ExceptionPrinterJobListener - 作业中发生异常: GRAILS_JOBS。 消息:java.lang.IllegalStateException:未找到线程绑定请求:您指的是实际之外的请求属性 Web 请求,或处理原始请求之外的请求 接收线程?如果您实际上是在 Web 请求中操作 仍然收到此消息,您的代码可能在外面运行 DispatcherServlet/DispatcherPortlet:在这种情况下,使用 RequestContextListener 或 RequestContextFilter 暴露当前 要求。 线 |方法 ->> 96 |在 grails.plugins.quartz.GrailsJobFactory$GrailsJob 中执行 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 216 |在 org.quartz.core.JobRunShell 中运行 ^ 549 |跑步 。 .在 org.quartz.simpl.SimpleThreadPool$WorkerThread
由 IllegalStateException 引起:未找到线程绑定请求:您指的是 请求实际网络之外的属性 请求,或处理原始接收之外的请求 线?如果您实际上是在 Web 请求中操作并且仍然 收到此消息,您的代码可能在 DispatcherServlet/DispatcherPortlet:在这种情况下,使用 RequestContextListener 或 RequestContextFilter 暴露当前 要求。 ->> 131 | org.springframework.web.context.request.RequestContextHolder 中的 currentRequestAttributes"

这是我的代码:

 def execute() {
     pingService.checkPing()
 }



 def checkPing = {
     User user = User.findByLogin(session.user.login) //get user
     def hostsToPing = importFromDB()
     if (!hostsToPing.isEmpty()) {
         hostsToPing.each {host ->
             doPing(host)
         }
     } else {
         //something else
     }
 }

 def importFromDB = {
     User user = User.findByLogin(session.user.login)
     def hostsList = Host.findAllByUser(user)
     hostsList
 }

 def doPing(Host host) {
     println "InetAdress: " + InetAddress.getByName(host.hostAdress)
     println "InetAdress is Rea: " + InetAddress.getLocalHost().isReachable(1000)
 }

当是这样的时候就不存在这个问题了:

def doPing(Host host) {
    println "InetAdress: " + InetAddress.getByName("www.google.com")
    println "InetAdress is Reachable : " + InetAddress.getLocalHost().isReachable(1000)
}

有谁知道怎么回事?

【问题讨论】:

    标签: grails quartz-scheduler


    【解决方案1】:

    因为你指的是session.user.loginJob 期间没有 session。 想象一下,当没有用户登录时,工作就开始了——那你指的是什么用户?

    所以要么检查User.list() 中的每个用户,要么创建一个带有用户队列的单例bean。

    【讨论】:

    • 谢谢,我会尝试使用 User.list()。
    猜你喜欢
    • 1970-01-01
    • 2011-05-01
    • 1970-01-01
    • 2020-08-28
    • 2016-08-07
    • 1970-01-01
    • 2015-03-30
    • 2015-01-05
    • 1970-01-01
    相关资源
    最近更新 更多