Grails quartz->thread

北慕城南 提交于 2019-12-11 06:56:42

问题


This is my Trigger that calls a matchService...

    class TestJob { 
     def matchService

 static triggers = {

  cron name: 'firstThread',  cronExpression: "0 0/1 12-13 ? * THU"
  }

 def group = "threadGroup"


    def execute() {
  matchService.playMatch()
  println "run thread: " + String.format('%tH:%<tM:%<tS.%<tL',System.currentTimeMillis())
    }
}

...this is the service that is called

class MatchException extends RuntimeException {
 String message
 Match match
}


class MatchService {

     /*
      * Rolls back database changes if errors occur
      */
     static transactional = true

     public void calc(Match m) {
      println m.teamH.name + " - " + m.teamA.name
     }

     public playMatch() {

      List<Match> matchList = new ArrayList()

      Cal.get(1).matches.each{
       match ->
        matchList.add(match)
      }


    for(Match m: matchList) {
       if(!m.validate()) {
        throw new MatchException( message: "match not valid!!" , match:m)
       }
        calc(m)
    }
   }
 }

what I'd like to do is to call the method calc N times in N threads to run synchronized. Is it also possible to update a gsp page in real time (without refresh the browser) with the new changes? Anybody can help me?


回答1:


why dont you just write a controller method in your grails app and use javascript and ajax to update the page.

Take a look at this plugin for periodically updating a html page with and ajax call to the server

http://github.com/RobertFischer/JQuery-PeriodicalUpdater/




回答2:


You can't refer to 'm' like you do in that example. You need to pass the match into the Runnable somehow.

This is where you could use the background-thread plugin to save you some coding.

cheers

Lee



来源:https://stackoverflow.com/questions/4042492/grails-quartz-thread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!