views:

46

answers:

2

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?

A: 

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/

Aaron Saunders
A: 

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

leebutts