Code Monkey home page Code Monkey logo

Comments (8)

hakanai avatar hakanai commented on September 13, 2024

Well, it seems like no workaround I try is really working either. I tried doing the startup of our service separately but then there is a risk of the service initialisation starting up at the same time, which appears to cause JNA to deadlock. If the service control dispatcher is running, another thread attempting to make a JNA call stalls and never completes. Since we use JNA to fetch information about system memory for outputting a diagnostics line, this kills us before the first line of text is written to the log.

I tried separating it such that we delayed our own startup (using locks) until the service onStart() callback has been called, but that is apparently no use either - if we do it this way around, onStart() is never called.

The frustrating thing is that I can't see what's wrong in my code which makes it fail whereas YAJSW supposedly works. The next step of course is to see if YAJSW actually works.

from jna.

twall avatar twall commented on September 13, 2024

Check your classpath. I believe the NTService stuff samples the classpath when you install the service (via Java) in order to set up the service callback parameters. This is potentially something that YAJSW might handle differently.

from jna.

hakanai avatar hakanai commented on September 13, 2024

My workaround is to do the startup code outside the callback, and this works, so clearly the classes I'm calling are on the classpath. Unless somehow the service wrapper is changing the classpath before calling onStart(), which would be really bad.

Our service itself launches via an .exe which sets up the classpath properly. Also, the executable we run as a command-line app is the same executable we use to run the service - we just fall back to starting up normally if we get told we don't have permission to start up as a service.

I have just checked the value of the java.class.path system property from inside onStart() anyway and it's the same value I get if I look it up immediately after startup.

from jna.

twall avatar twall commented on September 13, 2024

How does the ntservice code compare to that within the platform library? Any improvements in the former should be incorporated into the latter and the ntservice version dropped.

from jna.

dblock avatar dblock commented on September 13, 2024

The platform version was a port of the example, with fixes, cleanup and tests done by Eugene Levitov. There's a bit of work remaining there to add an actual service and extend tests per the TODOs in W32ServiceTests.java.

The contrib version should be using this and serve as an example. But that was never finished, PRs welcome.

from jna.

hakanai avatar hakanai commented on September 13, 2024

Evidence on stackoverflow that this might be a common problem related to JNI:

http://stackoverflow.com/questions/10514495/service-loader-does-not-locate-service-provider-class-even-though-class-is-in-s

But what doesn't make sense is, our main application launcher uses JNI to launch the JVM in the first place. So why does that work, when this doesn't?

from jna.

hakanai avatar hakanai commented on September 13, 2024

Thread.currentThread().getContextClassLoader() returns an instance of AppClassLoader on the main thread but in the callback, it returns null.

Putting in a hack to set it properly after the callback is called seems to fix the issue, so maybe all that JNA has to do is set the context class loader when calling any callbacks?

I still don't understand this though. How did ServiceLoader manage to load the services file, if it didn't have the right ClassLoader?

from jna.

hakanai avatar hakanai commented on September 13, 2024

Closing since I don't use the class anymore and it seems like nobody else has joined.

from jna.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.