Feeds:
文章
迴響

Archive for the ‘Java’ Category

[Java8][Nashorn] 多執行緒

使用 Java.lang.Thread 讓 Javascript 具有多執行緒功能

thread.js

var Run = Java.type(“java.lang.Runnable");

var MyRun = Java.extend(Run, {

    run: function() {

        while(true){

            print(“Run in separate thread");

        }

    }

});

var Thread = Java.type(“java.lang.Thread");

var th = new Thread(new MyRun());

th.start();

while(true){

    print(“main thread");

}

廣告

Read Full Post »

測試 javascript 使用 Java Class, 外部 JAR

use_java_class.js

20140424-04

 

 

參考資料

http://docs.oracle.com/javase/8/docs/technotes/guides/scripting/nashorn/api.html

Read Full Post »

參考 http://docs.oracle.com/javase/8/docs/technotes/guides/scripting/nashorn/shell.html

 

shell.js

20140424-03

Read Full Post »

蠻 Cool 只是啟動速度有點慢

javafx.js

20140424-01

20140424-02

Read Full Post »

import static java.lang.System.out;
import java.lang.reflect.Field;

public class Test {
    publicstaticvoid main(String[] args) {
        for (final Field field :Double.class.getDeclaredFields()){
           try {
                if(field.getName().equals("BYTES")){
                    out.println(field.get(null)); // Double = 8 bytes
                }
           }catch (IllegalAccessException illegalAccess){
                out.println("ERROR: Unable to reflect on field \"BYTES\"");
           }
        }
    }
}

參考資料
[1]http://www.javacodegeeks.com/2014/04/programmatic-access-to-sizes-of-java-primitive-types.html

Read Full Post »