Comments (8)
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.
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.
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.
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.
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.
Evidence on stackoverflow that this might be a common problem related to JNI:
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.
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.
Closing since I don't use the class anymore and it seems like nobody else has joined.
from jna.
Related Issues (20)
- Loading dll crashing + not up to date complation HOT 1
- IndexOutOfBoundsException in ELFSectionHeaders runnning on old IcedTea Java 8 version on ARMv7 HOT 7
- Monitor JNA's security posture with the Scorecard Action HOT 5
- Android Unable to load library from android-aarch64 HOT 1
- The free_callback function has a JNI weak global reference leak problem HOT 6
- loongarch64 need glibc2.36 HOT 29
- Consider adding M1 test on CI HOT 5
- Cannot run unsigned DLLs from user writeable PATH (windows) HOT 2
- Appveyor CI is broken HOT 3
- Enable RELRO HOT 4
- Collate License File Content HOT 1
- struct get different result with same code and process same data HOT 1
- JNA 7.0.0 Incompatible Native Library. HOT 1
- Segfault in jnadispatch.dll HOT 4
- Please provide a method for getting the NativeLibrary instance from Library interface
- Very heavy lock contention under load
- Loading jnidispatch on Android 15 with 16 KB page size leads to crash
- this ratted me pc pls help
- The binary is not signed for version 5.14.0 HOT 1
- `linux-riscv64` was not synced in MANIFEST.MF on jna-5.14.0.jar
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jna.