Sharing dynamically loaded classes with JShell instance

后端 未结 3 756
不知归路
不知归路 2021-01-31 18:45

Please view the edits below

I\'m trying to create a JShell instance that gives me access to, and lets me interact with objects in the <

3条回答
  •  眼角桃花
    2021-01-31 18:49

    only speaking to a small part of this rather substantial question:

    Additionally, exchanging DirectExecutionControl with LocalExecutionControl gives the same results, but I do not understand the difference between the two classes

    LocalExecutionControl extends DirectExecutionControl and it overrides only invoke(Method method), the bodies of which are ...

    local:

        Thread snippetThread = new Thread(execThreadGroup, () -> {
                ...
                res[0] = doitMethod.invoke(null, new Object[0]);
                ...
        });
    

    direct:

        Object res = doitMethod.invoke(null, new Object[0]);
    

    so the difference between the two classes is that direct invokes the method in the current thread, and local invokes it in a new thread. the same classloader is used in both cases, so you'd expect the same results in terms of sharing memory and loaded classes

提交回复
热议问题