2009 Mar 23 3:41 PM
Hello
As per my understanding the Singleton is supposed to have only one instance of class per user session.
However, I am in doubt that whether Singleton is instantiated only once for multiple user sessions. Can any one validate this idea and have a definite answer ?
If singleton is instantiated only once per client (meaning multiple user sessions) will that be one singleton class used for all sessions ?
I would greatly appreciate your help and comments..
Best regards
Vijay
Edited by: jakk on Mar 23, 2009 8:41 PM
2009 Mar 23 6:11 PM
>
> I am in doubt that whether Singleton is instantiated only once for multiple user sessions.
No, that is not the case.
Hello
As per my understanding the Singleton is supposed to have only one instance of class per user session.
However, I am in doubt that whether Singleton is instantiated only once for multiple user sessions. Can any one validate this idea and have a definite answer ?
If singleton is instantiated only once per client (meaning multiple user sessions) will that be one singleton class used for all sessions ?
I would greatly appreciate your help and comments..
Best regards
Vijay
Edited by: jakk on Mar 23, 2009 8:41 PM
2009 Mar 23 3:48 PM
Your understanding is correct: "one instance of class per user session".
It would create a new object for each different user session.
Try this sample code. Put a breakpoint in the method GET_OBJECT. Run the report, stop at the breakpoint. Now, start a new Session and run the report again and you will see that it would create a new object for the new session.
*----------------------------------------------------------------------*
* CLASS lcl_add DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_add DEFINITION CREATE PRIVATE.
PUBLIC SECTION.
CLASS-DATA: w_time TYPE sy-uzeit.
CLASS-METHODS:
get_object
EXPORTING
eo_add TYPE REF TO lcl_add.
PRIVATE SECTION.
CLASS-DATA: lo_add TYPE REF TO lcl_add.
ENDCLASS. "lcl_add DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_add IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_add IMPLEMENTATION.
METHOD get_object.
IF lcl_add=>lo_add IS INITIAL.
CREATE OBJECT lcl_add=>lo_add.
GET TIME FIELD w_time.
ENDIF.
eo_add = lcl_add=>lo_add.
ENDMETHOD. "get_object
ENDCLASS. "lcl_add IMPLEMENTATION
START-OF-SELECTION.
DATA: o_add TYPE REF TO lcl_add.
DATA: l_test TYPE char10.
l_test = 'TEST'.
CALL METHOD lcl_add=>get_object
IMPORTING
eo_add = o_add.
WRITE: / lcl_add=>w_time.
CLEAR o_add.
CALL METHOD lcl_add=>get_object
IMPORTING
eo_add = o_add.
WRITE: / lcl_add=>w_time.
Regards,
Naimesh Patel
2009 Mar 23 4:03 PM
The code that you gave is for a local singleton class. What would happen for Global Singleton class that is created from SE24 ?
Best regards
Vijay
Edited by: jakk on Mar 23, 2009 9:08 PM
2009 Mar 23 4:47 PM
That would remain same. Try with a global class same as this example local class.
Regards,
Naimesh Patel
2009 Mar 23 6:11 PM
>
> I am in doubt that whether Singleton is instantiated only once for multiple user sessions.
No, that is not the case.
2009 Mar 23 6:42 PM
Thank you Matt.
I was thinking from conceptual point of view; that a Singleton (Global Class created in SE24) is instantiated only once for a user session.
Even though user is same (in case of RFC CALLS) each session (LUW) has separate Singleton intance. I hope this is correct understanding.
Best regards
Vijay.
2009 Mar 23 8:09 PM
Yes. It is correct "Even though user is same (in case of RFC CALLS) each session (LUW) has separate Singleton intance".
Singleton object's life time is based on the internal ABAP Session.
Like:
If you have a Singleton object for some business requirement in the Sales Order Processing, than the singleton would be active till you left the order processing.
Regards
Naimesh Patel
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |