Invoking a java method from a non-java thread
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Shahram_Javidnia
Posted On:   Saturday, February 3, 2007 08:44 AM

I am working on a java class which enables TWAIN scanners for the rest of application (in win32 platform). The part of the class which actually communicates with the scanner is written natively using Delphi. I require native code to send a notification to java code by invoking a specific method on a specific object. To do so I have created an init() method in native code section which obtains the JVM instance from JNIEnv variable passed by JNI implementation and in the notify method, I use JVM instance to invoke AttachCurrentThread() method to obtain a JNIEnv instance. The problem is that at the point of sending notification, I get an ACCESS VIOLATION error.    More>>

I am working on a java class which enables TWAIN scanners for the rest of application (in win32 platform).
The part of the class which actually communicates with the scanner is written natively using Delphi.


I require native code to send a notification to java code by invoking a specific method on a specific object.


To do so I have created an init() method in native code section which obtains the JVM instance from JNIEnv variable passed by JNI implementation and in the notify method, I use JVM instance to invoke AttachCurrentThread() method to obtain a JNIEnv instance.


The problem is that at the point of sending notification, I get an ACCESS VIOLATION error.


I guess the cause of the problem is that when the user invokes scanner GUI, a new thread is created by TWAIN_32.dll (as specified by TWAIN standard) which bring the driver specific GUI and interacts with the user. And JNI prevents this thread to be attached to the JVM.


What should I do?

   <<Less

Re: Invoking a java method from a non-java thread

Posted By:   jacques_gonzalez  
Posted On:   Monday, February 12, 2007 02:12 PM

It’s difficult to diagnose from the cause of the error without any code, but if you want to solve your integration problem fast, you should take a look at “JX for Delphi Win32” at http://www.j4soft.com.


JX lets you call Java from Delphi Win32 applications using JX generated Delphi native classes that correspond to the Java classes you want to access and JX does also support multi-threading scenarios, i.e. using native threads with a JVM.


JX can also be used when calling Delphi code from Java.

About | Sitemap | Contact