开发者

Is possible to have 2 child threads with different classpath in each one?

开发者 https://www.devze.com 2023-01-12 11:06 出处:网络
I have a \"core\" application that is adapter to process task. Each task is i开发者_StackOverflow社区mplemented in an adapter load by the core to process the task.

I have a "core" application that is adapter to process task. Each task is i开发者_StackOverflow社区mplemented 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,


Indeed:

URLClassLoader cl = new URLClassLoader(urls);
Thread thread = new MyThread();
thread.setContextClassLoader(cl);
thread.start();


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消