2015-04-06 71 views
5

我現在正在GAE中開發一個java Google雲端點。在端點內部,它將嘗試連接到Firebase服務器以獲取一些數據。Google App Engine中的Firebase初始化錯誤

然而,當我創建我的端點火力地堡對象,

Firebase ref = new Firebase(<My Firebase URL>); 

GAE引發以下錯誤:

java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "modifyThreadGroup") 
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:382) 
    at java.security.AccessController.checkPermission(AccessController.java:572) 
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549) 
    at java.lang.ThreadGroup.checkAccess(ThreadGroup.java:315) 
    at java.lang.Thread.init(Thread.java:391) 
    at java.lang.Thread.init(Thread.java:349) 
    at java.lang.Thread.<init>(Thread.java:675) 
    at java.util.concurrent.Executors$DefaultThreadFactory.newThread(Executors.java:572) 
    at com.firebase.client.utilities.DefaultRunLoop$FirebaseThreadFactory.newThread(DefaultRunLoop.java:25) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.<init>(ThreadPoolExecutor.java:600) 
    at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:943) 
    at java.util.concurrent.ThreadPoolExecutor.ensurePrestart(ThreadPoolExecutor.java:1635) 
    at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:307) 
    at java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:526) 
    at java.util.concurrent.ScheduledThreadPoolExecutor.execute(ScheduledThreadPoolExecutor.java:615) 
    at com.firebase.client.utilities.DefaultRunLoop.scheduleNow(DefaultRunLoop.java:57) 
    at com.firebase.client.core.Repo.scheduleNow(Repo.java:176) 
    at com.firebase.client.core.Repo.<init>(Repo.java:58) 
    at com.firebase.client.core.RepoManager.getLocalRepo(RepoManager.java:46) 
    at com.firebase.client.core.RepoManager.getRepo(RepoManager.java:19) 
    at com.firebase.client.Firebase.<init>(Firebase.java:194) 
    at com.firebase.client.Firebase.<init>(Firebase.java:199) 
    at com.firebase.client.Firebase.<init>(Firebase.java:177) 

我使用火力地堡客戶端2.2.3。看起來GAE似乎不允許應用程序創建新線程。任何想法?

回答

3

@ Mario是正確的,App Engine應用程序可能不會根據docs產生新線程。這是因爲AppEngine應用程序在沙箱環境中運行,您有一些限制。如果仍然想要在沒有外出的情況下開發您的應用程序任何限制,那麼我會建議嘗試Managed VM其中你沒有這些類型的限制。

+1

實際上,你可以運行使用基本或手動縮放線程,而通過設置管理VM的所有麻煩去,唯一的限制是自動縮放:https://cloud.google.com/appengine/docs/ java/modules /#Java_Background_threads –

4

在用於Google App Engine的Java運行時,創建新線程有一些限制。

詳情請參閱the Threads section

-3

我認爲this鏈接將幫助你,它描述了我們如何使用服務帳戶從服務器應用程序使用firebase實時數據庫。

您可以使用以下代碼片段連接到Firebase數據庫。

// Initialize the app with a service account, granting admin privileges 
FirebaseOptions options = new FirebaseOptions.Builder() 
    .setDatabaseUrl("https://databaseName.firebaseio.com") 
    .setServiceAccount(new FileInputStream("path/to/serviceAccountCredentials.json")) 
    .build(); 
FirebaseApp.initializeApp(options); 

// As an admin, the app has access to read and write all data, regardless of Security Rules 
DatabaseReference ref = FirebaseDatabase 
    .getInstance() 
    .getReference("restricted_access/secret_document"); 
ref.addListenerForSingleValueEvent(new ValueEventListener() { 
    @Override 
    public void onDataChange(DataSnapshot dataSnapshot) { 
     Object document = dataSnapshot.getValue(); 
     System.out.println(document); 
    } 
}); 
+1

這沒有解決所述問題。上述代碼將以與原始文章完全相同的方式失敗。 –

+0

嗨@AaronSarazan,我在發佈之前測試過它,並且正在工作,如果您遇到任何錯誤,請在此處發佈。 –