1

I am using JPA2 @entity to represent my models. I need to put data asynchronously to the datastore. How would I do that? If a JPA Dao cannot do that, can I use AsyncDatastoreService on JPA entities -- instead of JPQL? Does anyone have an example?

(I know in Python this would be a joke as I can extend ndb.Model to create models and then call put_async on them. But in Java there is no ndb.Model to extend so I am using JPA.)

Michael Celey
  • 12,645
  • 6
  • 57
  • 62
learner
  • 11,490
  • 26
  • 97
  • 169
  • Sorry, but 1) Why not just use Python? and 2) What does this have to do with Cloud Endpoints? – bossylobster Mar 26 '13 at 21:17
  • @bossylobster `Cloud Endpoints` is for perspective to the reader. Why java? I am learning because some employers (mine) developing mobile on app-engine don't use python. – learner Mar 26 '13 at 21:31
  • @bossylobster it seems that you work for google. You don't like the java backend efforts such as GEP? – learner Mar 26 '13 at 21:49
  • I like Java just fine, was just curious if you were familiar with Python why you wouldn't use it. I now understand. – bossylobster Mar 26 '13 at 22:07

1 Answers1

1

I am very much hoping not to have to use the following ThreadManager.createBackgroundThread. But so far it's all I have found. Does anyone else have something much simpler (like python's put_async)?

import com.google.appengine.api.ThreadManager;
import java.util.concurrent.AtomicLong;

AtomicLong counter = new AtomicLong();

Thread thread = ThreadManager.createBackgroundThread(new Runnable() {
  public void run() {
    try {
      while (true) {
        counter.incrementAndGet();
        Thread.sleep(10);
      }
    } catch (InterruptedException ex) {
      throw new RuntimeException("Interrupted in loop:", ex);
    }
  }
});
thread.start();
learner
  • 11,490
  • 26
  • 97
  • 169