Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between getClass.getclassloader and tThread.getContextClassLoader

 
Sudarshan Sreenivasan
Ranch Hand
Posts: 188
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I wanted to know the difference between Thread.currentThread().getContextClassLoader() and getClass().getClassLoader()

This is what i got in the api's



Class.getClassLoader() returns the ClassLoader that loaded the class it
is invoked on.

Thread.getContextClassLoader() returns the ClassLoader set as the
context ClassLoader for the Thread it is invoked on



This is what i got after googling up this topic

Class.getClassLoader's classloader can be
different from the ClassLoader that loaded the Thread class itself if
the Thread's setContextClassLoader(ClassLoader) method has been invoked.



Now my question

If i have not called Thread's setContextClassLoader(ClassLoader) can the two methods return different classloaders in a j2ee environment ?

The reason for my asking is we use OC4J at work ... in certain rare situations.

Thread.currentThread().getContextClassLoader().getResourceAsStream(String name) does not seem to return the stream

However getClass().getClassLoader().getResourceAsStream(String name)
seems to get the job done.

Given the above info i need an explanation with scenario example preferably as to why i am being returned two different class loaders.


Thanks in advance.
 
Guido Sautter
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I'm not a Barender, I can't close this threa, but please do not post the same question in multiple forums !!
 
Sudarshan Sreenivasan
Ranch Hand
Posts: 188
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
posted here by mistake sorry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic