Problem calling "C" function multiple times in Java
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ramkumar_Sundaram
Posted On:   Friday, May 11, 2001 02:46 PM

Hi I have a java program that calls a "C" function thru JNI call. If the "C" function is called 4/5 times its working fine. But in case its called more than 7/8 times it hangs. I believe there is no bug in the "C" program. And also when it is called lesser no. of times its working fine. I attach the code below : ------------------------------- public class TestJni { public static void main(String a[]) { int nooftimes = 0; if(a[0] != null) { nooftimes = Integer.parseInt(a[0]); } else nooftimes = 3; for(int i=0; i < nooftimes ; i++) { ClassO   More>>

Hi

I have a java program that calls a "C" function thru JNI call. If the "C" function is called 4/5 times its working fine. But in case its called more than 7/8 times it hangs.

I believe there is no bug in the "C" program. And also when it is called lesser no. of times its working fine.

I attach the code below :


			
-------------------------------
public class TestJni
{

public static void main(String a[])
{
int nooftimes = 0;
if(a[0] != null)
{
nooftimes = Integer.parseInt(a[0]);
}
else
nooftimes = 3;

for(int i=0; i < nooftimes ; i++)
{
ClassOne objone = new ClassOne();
String str = objone.genString();
System.out.println("string is : " + str);
}
}

}

--------------------------------------

--------------------------------------

public class ClassOne
{
public native String genString();

static
{
System.out.println("Loading the Library : strgen");
System.loadLibrary("strgen");
System.out.println("Library : strgen Loaded");
}
}

----------------------------------------

I feel that the library which has been loaded is not getting unloaded.    <<Less

Re: Problem calling &quot;C&quot; function multiple times in Java

Posted By:   Alexander_Krapf  
Posted On:   Monday, May 14, 2001 08:02 AM

Hi Ramkumar,


You really need to post the native code too if you want help on this issue. The Java code alone is not very helpful.

My second observation is that you should make genString a static method.


Alex

About | Sitemap | Contact