NativeScript / NativeScript/android

questions about background threads

Đang mở
#1,262 6 bình luận 2 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
C++
Star
563
Fork
144
Merge trung bình
10 giờ 46 phút
Pull request đã merge (30 ngày)
14

Mô tả

I know you already said here that all JS runs in UI Thread but i would like to have another look at this.
The reason is that i found out that on IOS the Js code will run on the the thread in has been triggered.
This is actually an amazing feature. Thanks to that i managed to create an OpenCV module that can do live camera processing. In native the image processing is triggered from a background thread, then i call a JS delegate that modifies the image and returns it. All that happens in the background thread!.

It works amazingly. Imagine all the possibilities!
Now obviously i want to look at this on android. I immediately faced a wall on android as the runtime will always make sure the call to v8 JS will be done on the "worker" thread.
I wanted to try things so i decided to debug the runtime and modify the code so that it runs the v8 JS in the thread it is in.
To do that i simply modified the code to make it believe it is always in the worker thread
Now i get a weird error that i dont get. I end with a maximum call stack exceeded:

Process: org.nativescript.demovueopencv, PID: 2587
    java.lang.RuntimeException: An error occurred while executing doInBackground()
        at android.os.AsyncTask$3.done(AsyncTask.java:354)
        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
        at java.util.concurrent.FutureTask.run(FutureTask.java:271)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: com.tns.NativeScriptException: 
    Calling js method doInBackground failed
    
    RangeError: Maximum call stack size exceeded
    File: "file:///data/data/org.nativescript.demovueopencv/files/app/vendor.js, line: 39669, column: 14
    
    StackTrace: 
    	Frame: function:'ActivityCallbacksImplementation.onStart', file:'file:///data/data/org.nativescript.demovueopencv/files/app/vendor.js', line: 39669, column: 15
    	Frame: function:'NativeScriptActivity.onStart', file:'file:///data/data/org.nativescript.demovueopencv/files/app/vendor.js', line: 37027, column: 21
    
    
        at com.tns.Runtime.callJSMethodNative(Native Method)
        at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1162)
        at com.tns.Runtime.callJSMethodImpl(Runtime.java:1041)
        at com.tns.Runtime.callJSMethod(Runtime.java:1028)
        at com.tns.Runtime.callJSMethod(Runtime.java:1008)
        at com.tns.Runtime.callJSMethod(Runtime.java:1000)
        at android.os.AsyncTask_bundle_283_42_AsyncTaskRunner.doInBackground(Unknown Source:20)
        at android.os.AsyncTask$2.call(AsyncTask.java:333)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        	... 4 more

It seems to appear in the native side which i dont get.
Can someone guide me on this?

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với test-app/runtime/src/main/java/com/tns/Runtime.java, khoảng dòng 1152, và entry dispatchCallJSMethodNative ở dòng 1162. Tái hiện lời gọi từ một background thread và so sánh đệ quy ActivityCallbacksImplementation.onStart tạo ra với stack trace được báo cáo; công việc được xem là hoàn tất khi xác định được nguyên nhân và ghi lại hoặc khắc phục hành vi thread được hỗ trợ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
android, java, javascript
Lĩnh vực
mobile-dev
Loại issue
Lỗi
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
15/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.