Grails 石英->线

发布于 2024-09-29 17:23:00 字数 1150 浏览 0 评论 0原文

这是我的触发器,它调用 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())
    }
}

...这是被调用的服务,

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)
    }
   }
 }

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

双马尾 2024-10-06 17:23:00

为什么不在 Grails 应用程序中编写一个控制器方法并使用 javascript 和 ajax 来更新页面。

看一下这个插件,用于定期更新 html 页面并通过 ajax 调用服务器

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

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/

以酷 2024-10-06 17:23:00

您不能像该示例中那样引用“m”。您需要以某种方式将匹配传递到 Runnable 中。

您可以在此处使用后台线程插件来节省一些编码。

干杯

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文