Grails石英 - >螺纹 [英] Grails quartz->thread

查看:111
本文介绍了Grails石英 - >螺纹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的触发器,它调用了matchService ...

  class TestJob {
def matchService

静态触发器= {

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

)def group =threadGroup


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

...这是所谓的服务

$ p $ class MatchException extends RuntimeException {
字符串消息
匹配匹配
}


class MatchService {

/ *
* Rolls如果发生错误,则返回数据库更改
* /
static transactional = true

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

public playMatch(){

列表与LT;匹配> matchList = new ArrayList()

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


for(Match m:matchList){
if(!m.validate()){
抛出新的MatchException(消息:match not valid !!,match:m)
}
calc(m)
}
}
}

我想要做的就是在N个线程中调用N次方法calc来运行同步。
是否可以使用新更改实时更新gsp页面(不刷新浏览器)?
有人可以帮我吗?

解决方案

在这个例子中,你不能引用'm'。您需要以某种方式将匹配传递给Runnable。



这是您可以使用后台线程插件为您节省一些编码的地方。



欢呼



Lee


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?

解决方案

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

这篇关于Grails石英 - >螺纹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆