Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java Threads & pthreads - JNI

843829Dec 9 2004 — edited Dec 9 2004
Hi

I have an existing 3rd party library written in c++ which uses pthreads for Thread Local storage. I am building a wrapper around it in JNI and invoking it from a multi-threaded java client. Threads are created in java.

In each java thread , i call a native method which initializes the library where TLS is created. Do these thread models match ? I think so because when i invoke pthread_self() in the native method , i get different thread ids for differetn java threads.
Can i synchronize shared data using pthread_rwlock in this scenario ?

Can the TLS and synchronization using pthreads api be done when invoking from a multi threaded java application using JNI ?
I am trying to run it on Solaris and HP-UX.

I have tried using pthread_rwlock_,,, in the native method impl , it behaves in a different manner. Write lock is an exclusive one. but still a writer acquires the lock when multiple readers have it.

Synchronization is not a showstopper. but the TLS thing is . I only have binaries for the c++ library. so it cannot be changed. It will be nice of you if you can tell , what are the effects on using pthread TLS in a java multithreaded scenario. I am not creating any pthreads on the native side.

Please help me in this regard,

Thanks in advance
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 6 2005
Added on Dec 9 2004
1 comment
1,418 views