Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Virtual Machine / November 2006

Tip: Looking for answers? Try searching our database.

JNI  CallStaticVoidMethod fails after N calls

Thread view: 
santiago538@yahoo.com - 21 Nov 2006 13:47 GMT
I have written an application in Java and C on the Solaris 10 (x86)
platform using the JDK 1.5.0_09. The Java code calls a native method
"startButtonWatcher," which then forks, the parent process returning,
and the child process initiating an event loop that calls a static
method, "sendButtonEvent," on a Java class "ButtonWatcher."

The problem is that on the 65 invocation, the CallStaticVoidMethod will
hang. There is no core file or pid log file produced. (it will also
hang for CallVoidMethod as well if I remove the static declaration in
ButtonWatcher.)

I have also added a main() function to the C code so that it can be
compiled and run as an executable rather than a library file loaded
from Java, and the the same loop will be fine, the Call*Method call
being exected forever (or over a million times at least). The only
difference in the code is the JVM--in the sharable library, it uses the
JVM of the class that calls the native method, and the standalone has
to create its own. What could be the problem? Thanks!
Chris Uppal - 22 Nov 2006 14:59 GMT
> I have written an application in Java and C on the Solaris 10 (x86)
> platform using the JDK 1.5.0_09. The Java code calls a native method
> "startButtonWatcher," which then forks, the parent process returning,
> and the child process initiating an event loop that calls a static
> method, "sendButtonEvent," on a Java class "ButtonWatcher."

You mean you actually call fork() to create a new Unix process ??

If so then I'm extremely surprised that it works at all, let alone 64 times
before failing.

If not then I presume you mean that you start a new OS thread from your C code
(within the same Unix process).   In that case I'd suspect that you are doing
something "wrong" with your threads (or, also a plausible hypothesis
unfortunately, that Sun are doing something wrong with /their/ threads), and
that the difference in behaviour has little to do with the way the JVM is
launched.  Check that you are being completely clean about how you access
AWT/Swing objects, and that you don't do /anything/ to them except from code
runnng on the EDT.   Of course, that's only a guess; another possibility is
that you have a good old-fashioned deadlock which is not related to AWT at
all...

   -- chris
santiago538@yahoo.com - 22 Nov 2006 18:37 GMT
> > I have written an application in Java and C on the Solaris 10 (x86)
> > platform using the JDK 1.5.0_09. The Java code calls a native method
[quoted text clipped - 19 lines]
>
>     -- chris

Hi Chris,

I'm new to Unix programming, and I did use a fork(). I changed my code
to use pthreads instead and it works fine now. Thanks
Chris Uppal - 23 Nov 2006 11:41 GMT
> I'm new to Unix programming,

No shame in that!  ;-)

> and I did use a fork(). I changed my code
> to use pthreads instead and it works fine now.

I'm glad it's working properly now.  But I'm /really/ puzzled as to how the
earlier versions could have worked at all.  There must be something Very
Strange Indeed about how Solaris handles dynamic link libraries.

Oh well...

   -- chris


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.