Is possible to have 2 child threads with different

2019-03-22 09:07发布

I have a "core" application that is adapter to process task. Each task is implemented in an adapter load by the core to process the task.

My question is, is it possible to have different classpath in each adapter to precent class/jar conflict between adapters.

Regards,

3条回答
放我归山
2楼-- · 2019-03-22 09:46

Yes you can. using Thread's setContextClassLoader method.

check following link(little old but useful) for understanding it better:

http://www.javaworld.com/javaworld/javaqa/2003-06/01-qa-0606-load.html

查看更多
做个烂人
3楼-- · 2019-03-22 09:59

Indeed:

URLClassLoader cl = new URLClassLoader(urls);
Thread thread = new MyThread();
thread.setContextClassLoader(cl);
thread.start();
查看更多
Rolldiameter
4楼-- · 2019-03-22 10:04

Use Thread.currentThread().setContextClassloader() and make a new URLClassLoader with the desired classpath.

查看更多
登录 后发表回答