You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by Gurkan Erdogdu <cg...@gmail.com> on 2009/06/26 12:24:25 UTC

Using of ThreadContext ClassLoader

Hi;

In code base, several classes use thread context class loader  via calling
getContextClassLoader method (For Example : In ServicePool class uses
Thread.currentThread().getContextClassLoader(); ) without checking Security
Manager

Is it necessary to call this method within Priviledge Action?  And moreover,
what happens if this method returns null ?

PS : Sorry for my questions if it seems stupid. I just try to understand the
internal of the code base.

Thanks;

--Gurkan

Re: Using of ThreadContext ClassLoader

Posted by Gurkan Erdogdu <cg...@gmail.com>.
> Can that method return null?

Actually, Thread.currentThread().getContextClassLoader() may return null
when calling from "Native Libraries". For example, when I was integrating a
native library to integrate it into an application server via writing
resource adapter, there was a problem because
"Thread.currentThread().getContextClassLoader();" returns null and "Server
Security" internal code uses "thread context classloader" for getting
security related artifacts.

So I think, it is always a good idea to try defaults for getting class
loader if  *Thread.contextClassLoader* is null.

No, questions are great.  They help everyone understand the code better, not
> just you.  I love it when there's someone new on the project and they start
> asking all sorts of questions.  Usually brings out some good information and
> potential documentation.  Ask away!

Will do it :)

Thanks;

--Gurkan

2009/6/26 David Blevins <da...@visi.com>

>
> On Jun 26, 2009, at 3:24 AM, Gurkan Erdogdu wrote:
>
>  In code base, several classes use thread context class loader  via calling
>> getContextClassLoader method (For Example : In ServicePool class uses
>> Thread.currentThread().getContextClassLoader(); ) without checking
>> Security
>> Manager
>>
>> Is it necessary to call this method within Priviledge Action?
>>
>
> We aren't capable of running with a Security Manager installed, mostly due
> to third party libs. , so it's not really required currently.  If there
> isn't much overhead to doing the call we can  certainly add the doPrivilaged
> syntax.
>
>  And moreover,
>> what happens if this method returns null ?
>>
>
> Can that method return null?




>
>  PS : Sorry for my questions if it seems stupid. I just try to understand
>> the
>> internal of the code base.
>>
>
> No, questions are great.  They help everyone understand the code better,
> not just you.  I love it when there's someone new on the project and they
> start asking all sorts of questions.  Usually brings out some good
> information and potential documentation.  Ask away!
>
>
> -David
>
>
>
>
>


-- 
Gurkan Erdogdu
http://gurkanerdogdu.blogspot.com

Re: Using of ThreadContext ClassLoader

Posted by David Blevins <da...@visi.com>.
On Jun 26, 2009, at 3:24 AM, Gurkan Erdogdu wrote:

> In code base, several classes use thread context class loader  via  
> calling
> getContextClassLoader method (For Example : In ServicePool class uses
> Thread.currentThread().getContextClassLoader(); ) without checking  
> Security
> Manager
>
> Is it necessary to call this method within Priviledge Action?

We aren't capable of running with a Security Manager installed, mostly  
due to third party libs. , so it's not really required currently.  If  
there isn't much overhead to doing the call we can  certainly add the  
doPrivilaged syntax.

> And moreover,
> what happens if this method returns null ?

Can that method return null?

> PS : Sorry for my questions if it seems stupid. I just try to  
> understand the
> internal of the code base.

No, questions are great.  They help everyone understand the code  
better, not just you.  I love it when there's someone new on the  
project and they start asking all sorts of questions.  Usually brings  
out some good information and potential documentation.  Ask away!


-David