How do you get java.util.concurrent.Executor or CompletionService to work with Google AppEngine? Classes are officially a whitelist , but when you try to send asynchronous tasks, a security error occurs at runtime.
the code:
// uses the async API but this factory makes it so that tasks really // happen sequentially Executor executor = java.util.concurrent.Executors.newSingleThreadExecutor(); // wrap Executor in CompletionService CompletionService<String> completionService = new ExecutorCompletionService<String>(executor); final SomeTask someTask = new SomeTask(); // this line throws exception completionService.submit(new Callable<String>(){ public String call() { return someTask.doNothing("blah"); } }); // alternately, send Runnable task directly to Executor, // which also throws an exception executor.execute(new Runnable(){ public void run() { someTask.doNothing("blah"); } }); } private class SomeTask{ public String doNothing(String message){ return message; } }
An exception:
java.security.AccessControlException: access denied (java.lang.RuntimePermission modifyThreadGroup) when java.security.AccessControlContext.checkPermission (AccessControlContext.java:323) in java.security.AccessController.checkPermission (AccessController.java.lang46) .SecurityManager.checkPermission (SecurityManager.java//32) in com.google.appengine.tools.development.DevAppServerFactory $ CustomSecurityManager.checkPermission (DevAppServerFactory.java:166) in com.google.appengine.tools.apperer.Deverver.Device (DevAppServerFactory.java:191) in java.lang.ThreadGroup.checkAccess (ThreadGroup.java:288) in java.lang.Thread.init (Thread.javahaps32) in java.lang.Thread. (Thread.javaPoint65) in java.util.concurrent.Executors $ DefaultThreadFactory.newThread (Executors.java//42) in java.util.concurrent.ThreadPoolExecutor.addThread (ThreadPoolExecutor.java:672) in java.util.concurrent. ThreadPoolExecutor.addIfUnderCorePoolSize (ThreadPoolExecutor.java:697) in java.util.concurrent.ThreadPoolExecutor.execute (ThreadPoolExecutor.java:652) in java.util.concurrent.Executors $ DelegatedExecutorService.exavaute .concurrent.ExecutorCompletionService.submit (ExecutorCompletionService.java:152)
This code works great when running on Tomcat or using the JVM command line. However, it is clamped in the Jetty AppEngine SDK container (used with the Eclipse plugin and the maven-gae plugin).
AppEngine was probably designed to not run potentially dangerous programs, so I could see that they completely disabled thread creation. However, why does Google allow you to create a class but not allow you to call methods on it? The whitelist java.util.concurrent is misleading.
Is there any other way to perform parallel / simultaneous / parallel tasks in GAE?
source share