Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
JNI and java threading
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

JNI and java threading

I am going to more or less cross-post this since there may be people on different lists with more experience in the domains concerned, OS X, etc.
Although probably more appropriate to macosx-port than this list.
I have posted a question to the openjdk nio-dev list but aren't seeing any suggestions yet.

I have JNI that implements a kqueue Java 7 nio.2 WatchService. Part of my trz package below.
I am having trouble getting that to run the nio.2 stress test  LotsOfEvents.

Basically, the test, at this point, creates 4096 files in a temp directory and then sleeps a while to try to build up a backlog.
Then it invokes a timed poll method against the events.
The first time this finds maybe 25-45 of the create events that have been called back from the native to java.
Then the test tries to timer re-poll for 2 seconds to see if it gets more.
For some reason the native thread posts no new events in that time period and the test fails.
Almost right after the test fails the native code resumes posting event callbacks until the error caused test shutdown completes. 

Is there some reason the java thread(s) are blocking the native thread? Has anyone run into similar.

What the native does…
// Start new thread that fetches and processes our events:
keepThreadRunning = YES;
[NSThread detachNewThreadSelector:@selector(watcherThread:) toTarget:self withObject:nil];

It appears to be at the kevent invocation during the 'blocked' period.
    struct timespec     timeout = { 5, 0 }; // 5 seconds timeout.
n = kevent64( queueFD, NULL, 0, &ev, 1, 0, &timeout );

This is the one time I've done anything with kqueue so maybe there is something I'm not understanding right there. Is there some reason I'm not aware of that it would go into an extended wait? With this invocation it normally seems to have about 12 events/sec throughput. Why would it go 3 seconds+ with 0 unless java is somehow blocking or priority pre-empting it? Is there some way I can be sure to get it to fire in time to keep the java 2 second poll alive?

Roughly what the java does for completeness….
       WatchKey key = watcher.poll(15, TimeUnit.SECONDS);
        while (key != null) {
            List<WatchEvent<?>> events = key.pollEvents();
            for (WatchEvent<?> event: events) {
            key = watcher.poll(2, TimeUnit.SECONDS);

Michael Hall

AppConverter convert Apple jvm to openjdk apps

Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

Visit the Apple Store online or at retail locations.

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.