• Post Reply Bookmark Topic Watch Topic
  • New Topic

Changing Classloader of My Thread

 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to change the default class loader for loading all my classes in my thread. I tried





But the new classes created by 'new Myclassses()' doesn't seem to be loaded by my CustomLoader. What should be the proper way to do this?
 
Adam Smolnik
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey.

I don't know for sure. I will try it this evening. But at a glance I would rather set it after a thread creation and BEFORE starting it.
Docs says:


...
setContextClassLoader
public void setContextClassLoader(ClassLoader cl)
...
Sets the context ClassLoader for this Thread. The context ClassLoader can be set when a thread is created, and allows the creator of the thread to provide the appropriate class loader to code running in the thread when loading classes and resources.


Adam
 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about if the thread isn't created by me? It is created by some container/3rd party classes.
 
Adam Smolnik
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey.

If you aren't the thread owner you rather should NOT change the main rules established by creator/owner. He is responsible for managing this thread and he maybe took some assumptions which can be changed unawarely by you. Eventually, it can lead to an unpredictable behaviour of the container/framework.
But, you are always able to create your own thread to perform tasks if you need.

If of course specification of the container/framework permits it or at least doesn't forbid it explicitly.

Adam
 
Adam Smolnik
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey.

I am wrong with that subject. I've found the following example:

http://java.sun.com/products/jndi/tutorial/beyond/misc/classloader.html

Adam
 
Adam Smolnik
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey.

Concluding this topic, the context classloader can be used only explicitly via Thread.currentThread().getContextClassLoader to load some classes, resources etc..

Adam
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!