How to call javascript callback from java applets thread?

I have long Java code running in a thread running a Java applet. As soon as the code ends, it has information for the user. I would like to pass this information into a JavaScript callback in a thread-safe manner. Just using the Java DOM API to modify an HTML document is not good enough unless my JavaScript callback is called as a side effect in a thread safe way (i.e., ultimately in the same browser thread where the JavaScript callbacks are executed). How can i implement this? Are there any libraries that already do this?

+3
source share
3 answers

There seems to be no public textbook on how to do this. The entire Java JavaScript interface is underestimated, and it depends on browser restrictions.

0
source

It looks like the Common DOM API is what you need. Essentially, you are requesting a DOMService to call you back to the main UI thread when it is good and ready.

http://docs.oracle.com/javase/1.5.0/docs/guide/plugin/developer_guide/java_js.html

As I understand it, JSObject is the "old way", and the Common DOM API is the newer one (since Java 6). What you need to do is call the method of your applet and pass the object to the function you want to call back. Then your applet calls this function object from your DOMAction.

, , , Java. NPAPI, ++, JS ++, , , ++ JS. ", .

+2

concurrency , Javascript. Internet Explorer 8 (Firefox 3.6 Safari 5 ).

Javascript DOMService.invokeAndWait - .

, Java- > Javascript , ( - , , Javascript - ).

, Executors.newSingleThreadExecutor

+1
source

Source: https://habr.com/ru/post/1762188/


All Articles