You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Antony Scerri (JIRA)" <ji...@apache.org> on 2010/06/25 21:57:50 UTC

[jira] Commented: (DAEMON-100) Thread.currentThread().getContextClassLoader() == null when the program is runned by Prunsrv

    [ https://issues.apache.org/jira/browse/DAEMON-100?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12882691#action_12882691 ] 

Antony Scerri commented on DAEMON-100:
--------------------------------------

Sorry to do this a little messily but i have a number of different contribution so a single patch isnt possible. I believe the solution to this problem which I encountered whilst handling an application hosting an RMI registry which was generating class not found exception when registering objects because of this lack of fully supporting class loader is the modification of the __apxJavaWorkerThread method in javajni.c. I have attached an updated version of this method with just the parts relating to this problem.

Essentialy all it does is after the native thread is attached to the VM (which is different from the one which creates the main class. It checks to see if a thread context class loader can be found, this is incase the same thread that created the main class is now being used in which case it should already have one. I know this isnt the case at the moment but incase the design changes i thought it worth putting it inside a check. If not it then gets the class loader from the main class and assigns it to the current threads context class loader, therefore providing a fully functional class loader for the thread itself.

There could be some more exception checking between all the calls added with appropriate failure paths, but this should be enough to demonstrate the core fix. I have succesffuly used this to get a java application loaded on windows through the prunsrv.exe that creates an RMI registry and registers objects appropriately.

> Thread.currentThread().getContextClassLoader() == null when the program is runned by Prunsrv
> --------------------------------------------------------------------------------------------
>
>                 Key: DAEMON-100
>                 URL: https://issues.apache.org/jira/browse/DAEMON-100
>             Project: Commons Daemon
>          Issue Type: Bug
>          Components: Procrun
>         Environment: Win XP, jre1.5.0_11, -Djava.security.policy=<path to a file with following content>:
> grant  {
>     permission java.security.AllPermission "", "";
>     permission com.sun.rmi.rmid.ExecPermission "<<ALL FILES>>";
>     permission com.sun.rmi.rmid.ExecOptionPermission "*";
> };
>            Reporter: Anton Vodonosov
>         Attachments: __apxJavaWorkerThread.txt, DaemonLoader.patch
>
>
> Thread.currentThread().getContextClassLoader() == null when the program is runned by Prunsrv, but when we run the same system using java.exe, Thread.currentThread().getContextClassLoader() is not null.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.