• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

How to call java method from c function??

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
How can we call the java method from c function??
Can any body have resources in this issue???
send to [email protected]
Thanks advance
Srini
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am transferring this question to Java in General ( intermediate ) forum. Please use the JavaRanch forum only for issues related to the site and not for any technical discussions.
Thanks!
 
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am also interested in knowing the answer to this question. I have thought of ways, but none are very good regarding performance.
1. The c program invokes the jvm and runs a java program which listens for connections over socket. Then this c program communicates with the java using sockets.
2. Sim to first. Only the communication is thru shared data files.
 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Shubhrajit Chatterjee:

1. The c program invokes the jvm and runs a java program which listens for connections over socket. Then this c program communicates with the java using sockets.


That is what CORBA does, of course, with all the bells and whistles.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gali and Shubhrajit,
I think the network option is still the best, even if not very good in terms of perf. If you go for that solution, consider using XML/RPC or SOAP.
Another solution would be to use JNI (Java Native Interface). Using the invocation API (see below), your C code can create a java virtual machine that communicates with your application.
The initialisation code should look like that:

Once created, you attach your thread to the JVM using the AttachCurrentThread method.
You can then call methods on java objects using the GetObjectClass, GetMethodID and CallXXXMethod methods on the JVM environment.
You can then detach your thread from the VM once finished.
See the tutorial on JNI on the Sun website: http://java.sun.com/docs/books/tutorial/native1.1/
The tutorial mentions that the JDK only supports attaching native threads on Win32. This was true at the time of writing but it is now possible on other systems (e.g. Solaris, Linux, etc...) as native threads are now available on those other OS.
Hope this helps,
Beno�t
[This message has been edited by Beno�t d'Oncieu (edited December 19, 2001).]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic