<< Back to previous view

[CLJ-1223] Improve App Engine Support by Providing an Option to Use the App Engine ThreadManger Created: 22/Jun/13  Updated: 03/Sep/13

Status: Open
Project: Clojure
Component/s: None
Affects Version/s: Release 1.5
Fix Version/s: None

Type: Enhancement Priority: Minor
Reporter: James Thornton Assignee: Unassigned
Resolution: Unresolved Votes: 1
Labels: None
Environment:

Google App Engine



 Description   

Clojure support for App Engine can be improved now that App Engine supports sockets and threads.

Sockets
https://developers.google.com/appengine/docs/java/sockets/overview

Threads
https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/ThreadManager

The new sockets API uses java.net.Socket so it should just work without much/any modification to core. The Sockets API is an important addition because it enables you to connect to Compute Engine servers from App Engine without having to use the HTTP client.

Presently Clojure's agents and futures do not work on App Engine, but the new ThreadManager API now allows you to execute short-lived threads; however, you must use the ThreadManger API to create threads – "you cannot invoke new Thread() yourself or use the default thread factory" and "each request is limited to 50 concurrent request threads" – so adding support for threads will require a build option and some modifications.

Supporting agents on App Engine could be done by adding a Clojure build option for App Engine that includes the App Engine JDK dependency and injects the App Engine TreadManager factory into jvm/clojure/lang/Agent.java .

Google App Engine SDK for Java
https://developers.google.com/appengine/downloads#Google_App_Engine_SDK_for_Java

See also https://developers.google.com/appengine/docs/java/runtime#The_Sandbox ...

A Java application can create a new thread, but there are some restrictions on how to do it. These threads can't "outlive" the request that creates them. (On a backend server, an application can spawn a background thread, a thread that can "outlive" the request that creates it.)

An application can...

Implement java.lang.Runnable; and
Create a thread factory by calling com.google.appengine.api.ThreadManager.currentRequestThreadFactory()
call the factory's newRequestThread method, passing in the Runnable, newRequestThread(runnable)
or use the factory object returned by com.google.appengine.api.ThreadManager.currentRequestThreadFactory() with an ExecutorService (e.g., callExecutors.newCachedThreadPool(factory)).

However, you must use one of the methods on ThreadManager to create your threads. You cannot invoke new Thread() yourself or use the default thread factory.

An application can perform operations against the current thread, such as thread.interrupt().

Each request is limited to 50 concurrent request threads.

App Engine JRE Whitelist:
https://developers.google.com/appengine/docs/java/jrewhitelist

From the current App Engine Magic README (https://github.com/gcv/appengine-magic)...

"Google App Engine maintains a whitelist of permitted classes in Java's standard library. Other classes will cause your application to fail to deploy. Examples include threads and sockets. If you use those in your application, it will not work. This means that you cannot use Clojure's agents or futures. In addition, if one of your dependencies uses those, your application will also not work. For example, clojure.java.io (and its fore-runner, duck-streams from clojure-contrib), uses java.net.Socket, a forbidden class."


Generated at Thu Oct 23 01:24:43 CDT 2014 using JIRA 4.4#649-r158309.