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 / General / November 2006

Tip: Looking for answers? Try searching our database.

About FileXXXputStream 's implementation

Thread view: 
仁者无敌 - 17 Nov 2006 11:34 GMT
what's the native initIDs method of it used for?
Thomas Fritsch - 17 Nov 2006 12:19 GMT
仁者无敌 schrieb:
> what's the native initIDs method of it used for?

The initID method typically gets some JNI method IDs of the
FileXXXStream class and stores them somewhere in the C code. Later,
other native methods of the class can use these cached  method IDs to
call the non-native methods of the class.

Signature

Thomas

仁者无敌 - 17 Nov 2006 12:38 GMT
thx so much for your care.
That's my first question in this usenet.

Those ids are only used to call non-native method?
All jni method in C can use the first parameter to call non-native
method of that java object without any extra info,why those ids are
need?What things they really are?

On 11月17日, 下午8时19分, Thomas Fritsch
<i.dont.like.s...@invalid.com> wrote:
> 仁者无敌 schrieb:> what's the native initIDs method of it used for?The initID method typically gets some JNI method IDs of the
> FileXXXStream class and stores them somewhere in the C code. Later,
[quoted text clipped - 3 lines]
> --
> Thomas
仁者无敌 - 17 Nov 2006 12:46 GMT
By using the first two, I'm sorry,
"env" and "jobject"

en,but initIDs is a static native method, lack the "jobject"...

however,
this method is only called once in the static area,what did it store in
C code?

On 11月17日, 下午8时19分, Thomas Fritsch
<i.dont.like.s...@invalid.com> wrote:
> 仁者无敌 schrieb:> what's the native initIDs method of it used for?The initID method typically gets some JNI method IDs of the
> FileXXXStream class and stores them somewhere in the C code. Later,
[quoted text clipped - 3 lines]
> --
> Thomas
Gordon Beaton - 17 Nov 2006 13:00 GMT
On 17 Nov 2006 04:46:11 -0800, =?gb2312?B?yMrV387etdA=?= wrote:
> By using the first two, I'm sorry,
> "env" and "jobject"
>
> en,but initIDs is a static native method, lack the "jobject"...

Static methods have "jclass" instead.

> however, this method is only called once in the static area,what did
> it store in C code?

It makes calls to GetFieldID() to look up commonly used fields in the
class. This is a relatively expensive operation that only needs to be
done once for a given class. By caching the results the ids can be
reused by subsequent calls to the class's other native methods.

See section 10.7:
http://java.sun.com/docs/books/jni/html/pitfalls.html#29161

Why don't you get the source and check for yourself?

/gordon

Signature

[ don't email me support questions or followups ]
g o r d o n  +  n e w s  @  b a l d e r 1 3 . s e

Thomas Fritsch - 17 Nov 2006 13:23 GMT
仁者无敌 schrieb:
> On 11月17日, 下午8时19分, Thomas Fritsch
> <i.dont.like.s...@invalid.com> wrote:
[quoted text clipped - 9 lines]
>
> en,but initIDs is a static native method, lack the "jobject"...
You don't need it for getting method or field IDs.

> however,
> this method is only called once in the static area,what did it store
> in C code?
It might do for example look below:

#include "FileInputStream.h"

static jmethodID readMethodID;
static jmethodID closeMethodID;

void Java_FileInputStream_initIDs(JNIEnv *env, jclass c)
{
 readMethodID = env->GetMethodID(env, c, "read", "()I");
 closeMethodID = env->GetMethodID(env, c, "close", "()V");
}

void Java_FileInputStream_exampleMethod(JNIEnv *env, jobject obj)
{
 env->CallVoidMethod(env, obj, closeMethodID);
}

By the way: If you want a deeper understanding of JNI, I suggest you
work through Sun's JNI tutorial and/or a text-book.

Signature

Thomas

仁者无敌 - 17 Nov 2006 13:41 GMT
To Gordon,Thomas:
     Thanks for your help and suggestion.

On 11月17日, 下午9时23分, Thomas Fritsch
<i.dont.like.s...@invalid.com> wrote:
> 仁者无敌 schrieb:> On 11月17日, 下午8时19分, Thomas Fritsch
> > <i.dont.like.s...@invalid.com> wrote:
[quoted text clipped - 33 lines]
> --
> Thomas


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



©2009 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.