Grails 石英->线
这是我的触发器,它调用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不在 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/
您不能像该示例中那样引用“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