

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
5 messages in net.java.dev.jna.usersRe: [jna-users] Thread's ContextClass...| From | Sent On | Attachments |
|---|---|---|
| Thomas Börkel | Dec 4, 2008 3:52 am | |
| Timothy Wall | Dec 10, 2008 11:34 am | |
| Thomas Börkel | Dec 12, 2008 4:01 am | |
| Timothy Wall | Dec 12, 2008 5:19 am | |
| Thomas Börkel | Dec 12, 2008 11:52 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | Re: [jna-users] Thread's ContextClassLoader is null for Win32 services | Actions... |
|---|---|---|
| From: | Timothy Wall (twal...@dev.java.net) | |
| Date: | Dec 10, 2008 11:34:44 am | |
| List: | net.java.dev.jna.users | |
I don't think there's any requirement that the context class loader be non-null. Chances are the threads you're running on are different whether you're running on the console or as a service.
As a service, some threads are likely to be native threads which get attached to the VM on callbacks, which most certainly won't be the same as the console version.
On Dec 4, 2008, at 6:53 AM, Thomas Börkel wrote:
HI!
When my Java program is being started in the console, the ContextClassLoader (Thread.currentThread().getContextClassLoader()) is set.
But when the same program runs as Win32 service, the ContextClassLoader is null!
This also applies to new threads, that are being created by the program, not only the main thread.
Anyone any idea, why?
Attaching slightly modified TestService from JNA/contrib to show the problem.
Start with "java.exe -cp ... jnacontrib.win32.TestService x" and also as service.
The command line is exactly the same (besides the "x").
The ContextClassLoader is being written to C:\TestService.log.
Thanks!
Thomas /* * TestService.java * * Created on 12. September 2007, 12:49 * * To change this template, choose Tools | Template Manager * and open the template in the editor. */
package com.apag.p2plus.p2core.win32;
import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.logging.Level; import java.util.logging.Logger;
/** * TestService. */ public class TestService extends Win32Service {
/** * main. * @param args arguments */ public static void main(String[] args) throws Exception { TestService service = new TestService();
if(args.length == 1) {
if(args[0].equalsIgnoreCase("install")) { System.out.println(service.install("TestService DisplayName", "TestService Description", null, null, null));
} else if(args[0].equalsIgnoreCase("uninstall")) { System.out.println(service.uninstall());
} else if(args[0].equalsIgnoreCase("query")) { System.out.println(service.getStatus());
} else { System.out.println("Arguments:"); System.out.println("install = install service"); System.out.println("uninstall = uninstall service"); System.out.println("<none> = run service"); testClassLoader(); System.exit(0); }
} else { service.init(); } }
/** * Creates a new instance of TestService. */ public TestService() { super("TestService"); }
/** * Will be called on start. */ public void onStart() { log("onStart"); testClassLoader(); }
/** * Will be called on stop. */ public void onStop() { log("onStop"); }
public static void testClassLoader() { log("ContextClassLoader: " + Thread.currentThread().getContextClassLoader()); }
public static void log(String text) { try { PrintWriter pw; pw = new PrintWriter(new FileWriter(new File("C:\ \TestService.log"), true)); pw.println(text); pw.close(); } catch (IOException ex) { Logger.getLogger(TestService.class.getName()).log(Level.SEVERE, null, ex); } } }







