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!

Creating a new local ref from a weak ref because you need to call a method

843829Sep 9 2010 — edited Sep 11 2010
Hi,

I was looking at some jni code & I dont understand why you need to create a local reference from a weak one to call methods on it?

Heres the snippet:

if(NULL!=(local_ref = ((l_env.THIS))->NewLocalRef((l_env.THIS), weakRefListener)))*
*{*
l_class = ((l_env.THIS))->GetObjectClass((l_env.THIS), local_ref);*
if (l_class == ((l_env.THIS))->FindClass((l_env.THIS), "java/lang/ref/WeakReference"))*
*{*
if(NULL!=(methodID = ((l_env.THIS))->GetMethodID((l_env.THIS), l_class, (char*)"get", (char*)"()Ljava/lang/Object;")))*
*{*
strongRefListener = ((l_env.THIS))->CallObjectMethod((l_env.THIS), local_ref, methodID);*
*(*(l_env.THIS))->DeleteLocalRef((l_env.THIS), local_ref);*
*}*
*}*
else
*{*
strongRefListener = local_ref;
*}*

if (strongRefListener == NULL)
*{*
printf("failed to create strong reference");
*}*
else
*{*
*//* Call Java method *
*...... more code ..........*
*}*

Again I can't find any info as to why I need a strong reference or as to why I need to call a method "get" on it if its a weak reference. Does a weak reference get 'woken up' when invoked?


Thanks for reading this. I hope you understand it better than me.
Ryan

Edited by: mcCuppaT on Sep 9, 2010 3:35 AM

Edited by: mcCuppaT on Sep 9, 2010 3:35 AM

Comments

Solomon Yakobson
Answer
WITH SAMPLE(ID,FirstName,LastName,City,State,Phone,SystemDate)
  AS (
      SELECT 1,'John','Doe','ABC','FL','5555555555',DATE '2020-12-01' FROM DUAL UNION ALL
      SELECT 1,'John','Doe','ABC','FL','8888888888',DATE '2020-12-01' FROM DUAL UNION ALL
      SELECT 2,'Jane','Smith','XYZ','CA','9999999999',DATE '2020-12-01' FROM DUAL
     )
SELECT  ID,
        FirstName,
        LastName,
        City,
        State,
        LISTAGG(Phone,',') WITHIN GROUP(ORDER BY Phone) Phone,
        SystemDate
  FROM  SAMPLE
  GROUP BY ID,
           FirstName,
           LastName,
           City,
           State,
           SystemDate
/

        ID FIRS LASTN CIT ST PHONE                 SYSTEMDAT
---------- ---- ----- --- -- --------------------- ---------
         1 John Doe   ABC FL 5555555555,8888888888 01-DEC-20
         2 Jane Smith XYZ CA 9999999999            01-DEC-20


SQL>

SY.

Marked as Answer by User_OMEF8 · Dec 5 2020
User_OMEF8

Wow! That did the trick. Thanks so much! I did not realize it would be something as simple as that.

1 - 2
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Oct 9 2010
Added on Sep 9 2010
4 comments
257 views