Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jersey 2.0-rc1 does not start on Google App Engine because of new Timer/Thread creation #2111

Closed
jerseyrobot opened this issue Apr 9, 2013 · 8 comments

Comments

@jerseyrobot
Copy link
Contributor

Since 2.0-rc1 jersey can not start on GAE. It tries to init Timer/Thread but there are some limitations on GAE - https://developers.google.com/appengine/docs/java/runtime?hl=cs#The_Sandbox.

The AccessControlException is thrown:

WARNING: Nested in java.lang.ExceptionInInitializerError:
java.security.AccessControlException: access denied (java.lang.RuntimePermission modifyThreadGroup)
	at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
	at java.security.AccessController.checkPermission(AccessController.java:546)
	at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
	at com.google.appengine.tools.development.DevAppServerFactory$CustomSecurityManager.checkPermission(DevAppServerFactory.java:289)
	at com.google.appengine.tools.development.DevAppServerFactory$CustomSecurityManager.checkAccess(DevAppServerFactory.java:314)
	at java.lang.ThreadGroup.checkAccess(ThreadGroup.java:299)
	at java.lang.Thread.init(Thread.java:336)
	at java.lang.Thread.<init>(Thread.java:420)
	at java.util.TimerThread.<init>(Timer.java:456)
	at java.util.Timer.<init>(Timer.java:71)
	at org.glassfish.jersey.server.internal.JerseyRequestTimeoutHandler.<clinit>(JerseyRequestTimeoutHandler.java:65)
	at org.glassfish.jersey.servlet.internal.ResponseWriter.<init>(ResponseWriter.java:97)
	at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:297)
	at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:372)
	at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:335)
	at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:218)
	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
	at javax.servlet.FilterChain$doFilter.call(Unknown Source)
...

Change since 2.0-m13 (where it worked on GAE) was probably done by fixing #2044:
jersey/jersey@af357be
https://github.com/jersey/jersey/blob/af357bef3e93a61c87417c083d70d753c7efb51d/core-server/src/main/java/org/glassfish/jersey/server/internal/JerseyRequestTimeoutHandler.java

Environment

Google App Engine 1.7.6

Affected Versions

[2.0-rc1, 2.0]

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
Reported by shamoh

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
Issue-Links:
is related to
JERSEY-1853

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
shamoh said:
I suggest to provide SPI to get ThreadManager instance. You could create new jersey-gae module that will implement mentioned SPI to use GAE specific thread API:
https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/ThreadManager?hl=cs#currentRequestThreadFactory()

Then you cen use Executors.newSingleThreadScheduledExecutor(threadFactory) method to create ScheduledExecutorService. I hope ScheduledExecutorService can be used to schedule "TimerTask" functionality (see JerseyRequestTimeoutHandler).

GAE recomendation about hreads (https://developers.google.com/appengine/docs/java/runtime?hl=cs#The_Sandbox), capture The Sandbox / Threads:
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., call Executors.newCachedThreadPool(factory)).

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
@mpotociar said:
The actual Google AppEngine integration module implementation task.

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
@mpotociar said:
As part of this issue, only the requested Jersey SPI will be provided - org.glassfish.jersey.spi.RuntimeThreadProvider. At the moment, this SPI can be directly implemented by application developers who wish to run Jersey on GAE. A common GAE integration module will be implemented later as part of a separate task - #2125. (Community contribution in this area is welcome.)

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
Marked as fixed on Wednesday, April 17th 2013, 8:39:32 am

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
This issue was imported from java.net JIRA JERSEY-1839

@jerseyrobot
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant