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

后端 未结 3 1827
遇见更好的自我
遇见更好的自我 2021-02-11 05:36

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 possibl

相关标签:
3条回答
  • 2021-02-11 05:59

    Indeed:

    URLClassLoader cl = new URLClassLoader(urls);
    Thread thread = new MyThread();
    thread.setContextClassLoader(cl);
    thread.start();
    
    0 讨论(0)
  • 2021-02-11 06:04

    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 讨论(0)
  • 2021-02-11 06:07

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

    0 讨论(0)
提交回复
热议问题