multithreading - JPA and Threads in play framework -
i'm trying create multithreading server. problem following error: play.exceptions.jpaexception: jpa context not initialized. jpa entity manager automatically start when 1 or more classes annotated @javax.persistence.entity annotation found in application.
what i'm trying access db new thread here's code
package controllers; import java.util.iterator; import java.util.list; import models.ball; public class mainloop extends thread { @override public void run() { list<ball> balls; new ball(5,5,2,2,10,15); while (true){ balls = ball.all().fetch(); //here throws exception (iterator iterator = balls.iterator(); iterator.hasnext();) { ball ball = (ball) iterator.next(); ball.applyforces(); } } } }
any ideas?
don't use plain thread, use jobs instead :
@onapplicationstart public class mainloop extends job { public void dojob() { new balljob().now(); } }
and balljob :
public class balljob extends job { public void dojob() { list<ball> balls; new ball(5,5,2,2,10,15); while (true){ balls = ball.all().fetch(); (iterator iterator = balls.iterator(); iterator.hasnext();) { ball ball = (ball) iterator.next(); ball.applyforces(); } } }
Comments
Post a Comment