Using Static Variable against Context Attribute for Holding IWDView

Dear Friends,
I have a method which is in another DC which has a parameter of the type IWDView. In my view, I will have an action which will call the method in another component by passing the value for the view parameter. Here, I can achieve this in 2 types. One is - I declare a static variable and assign the wdDoModifyView's view as parameter value and I can pass this variable as parameter whenever calling that method or the second way - create an attribute and assign the same wdDoModifyView's view parameter as its value. Whenever I call this method, I can pass this attribute as parameter. What is the difference between these two types of holding the value since I am storing the same value i.e., wdDoModifyView's view parameter. But when I trigger the action from different user sessions, the first type of code (using static variable) prints the same value in both the sessions for view.hashCode() and View.toString(), but the same is printing the different values when I pass the attribute which holds the view parameter.
Clarification on this is highly appreciated
The problem I face is when I use static variable to get the view instance and export the data using the UI element's id, the data belonging to different user sessions is mixed up where as when I use Context Attribute, the same problem doesn't arise. I want to know the reason why it is so. Is there any other place or way where I can get the current view instance of each session instead of wdDoModifyView?

Hi Sujai ,
As you have specified the problem that we face when we use  static attributes, when end users are using the application .
Static means i  have n number of objects but the static variable value will remain same every where.
when it is context attribute for every object i.e nth object you have a nth context attribute i mean nth copy of the context attribute.
so every user has a unique Iview parameter , when context is used and
when static is used  , assume you have userA , his iview is set this intially  and u have another user B , when he is using  , since the variable is static and when you access this variable you will get the value of userA.
Regards
Govardan Raj

Similar Messages

  • Can I use static variable in EJB?

    Many books suggest developer don't use static variable in EJB,I want to know why?
    I know there isn't any problem if the static varibale is read only
    For writable static varible ,what will happen if I use a static Hashtable for share data
    Help me!Thank you very much!!

    Greetings,
    I know that "EJB business methods are not allowed to
    block on synchronized resources" Just where do you "know" that from?? The EJB 2.0 Specification, at least, is nowhere in agrement with this statement. If it comes from a book I would question the author's reasoning. Contractually, there's no sound basis for this. In the case of Session Beans, they have an expressedly direct and single-threaded association with a client. From a design viewpoint, it certainly seems unnecessary for a bean to "block" its one-and-only client, but to say that it "is not allowed to" do so is without merit. Entity Beans, on the other hand, are concurrently accessible. Yet, with regard to a transactional context being in effect, the container does indeed block on a bean's business methods. For the bean to do so itself is, therefore, unnecessary. Furthermore, the specification explicitly concedes that a "Bean Provider is typically an application domain expert" and "is not required to be an expert at system-level programming." (EJB 2.0 Spec. 3.1.1) From these statements alone it is reasonable to assume the above statement is meritless since the Bean Provider is not expected to even consider synchronization issues when developing a bean.
    But I'm mixed up why we could use "Hashtable" or otherApparently, because your sources are as well...
    collection classes in the EJB ,in these method many
    methods are synchronized In fact, not only "can we use" them but, with respect to multiple-row finders in Entity Beans we are [i]required to use them (or an iteration of them)! Not all Collection classes are synchronized (so called "heavy-weight collections"). As shown above, that the choice of a particular Collection class might be synchronized is of little consequence since a bean designed under strict adherence to the specification ensures that it is never concurrently writeable.
    Could someone provide a good way for this problem?
    Please Help Me!!!Regards,
    Tony "Vee Schade" Cook

  • When should I use static variable and when should not? Java essential

    When should I use static variable and when should not? Java essential

    Static => same value for all instances of the class.
    Non-static => each instance can have its own value.
    Which you need in which circumstances is completely up to you.

  • Setting Application Context Attributes for Enterprise Users Based on Roles

    Hello,
    We have an Oracle 11g database with a table containing data from multiple sites (a SiteID field identifies the site for a record). Since application users can have access to different subsets of sites, we would like to use Oracle's Virtual Private Database feature to enforce row-level security on the table.
    I did a successful proof-of-concept with database users. I created a role for each site (example: USER_SITE_A, USER_SITE_B, ...), and then assigned the appropriate site roles to each database user. I then created a package (run via a logon trigger) which set application context attributes for each site. If the current database user has been assigned a role for a given site, then the corresponding attribute named "SITE_PRIVILEGE_SiteID" is set to 'Y'... otherwise, it is set to 'N'. Here is the code which worked to set application context attributes for database users:
    -- For each record in my RoleSitePrivileges table, set
    --   an attribute named 'SITE_PRIVILEGE_<SiteID>'.
    --   If the current user has been assigned a role matching
    --   the value in the 'RoleName' field, set the corresponding
    --   attribute to 'Y'... otherwise, set it to 'N'.
    FOR iPrivRec IN (SELECT RoleName, SiteID
                       FROM RoleSitePrivileges
                       ORDER BY SiteID)
       LOOP
          SELECT COUNT(*)
            INTO roleExists
            FROM dba_role_privs
            WHERE granted_role = UPPER(iPrivRec.RoleName)
              AND grantee = USER;
          IF roleExists > 0 THEN
             DBMS_SESSION.set_context(
                         namespace   => 'my_ctx',
                         attribute   => 'SITE_PRIVILEGE_' || iPrivRec.SiteID,
                         value       => 'Y');
          ELSE
             DBMS_SESSION.set_context(
                         namespace   => 'my_ctx',
                         attribute   => 'SITE_PRIVILEGE_' || iPrivRec.SiteID,
                         value       => 'N');
          END IF;
       END LOOP;To finish things off, I created a security policy function for the table which returns the following:
    RETURN 'SiteID IN (SELECT TO_NUMBER(SUBSTR(attribute, 15))
                         FROM session_context
                         WHERE attribute LIKE ''SITE_PRIVILEGE_%''
                            AND value = ''Y'')';This setup worked great for database users. I am now working to do a comparable proof-of-concept for enterprise users created in Oracle Internet Directory (OiD). I have Enterprise User Security (EUS) up and running with OiD, global roles created in the database, enterprise roles defined in EUS with global role assignments, and enterprise roles assigned to OiD users. The enterprise users are able to successfully login to the database, and I can see the appropriate global role assignments when I query the session_roles view.
    I tried using the same application context package, logon trigger, and security policy function with the enterprise users that I had used with the database users. Unfortunately, I found that the application context attributes are not being set correctly. As you can see from the code above, the applicaiton context package was referencing the dba_role_privs view. Apparently, although this view is populated for database users, it is not populated for enterprise users.
    I tried changing the application context package to use invoker's rights and to query the session_roles view instead of the dba_role_privs view. Although this package sets the attributes correctly when called manually, it does not work when called from the logon trigger. That was an oops on my part, as I didn't realize initially that a PL/SQL procedure cannot be called with invoker's rights from a trigger.
    So, I am now wondering, is there another view that I could use in code called from a logon trigger to access the roles assigned to the enterprise user ? If not, is there a better way for me to approach this problem? From a maintenance standpoint, I like the idea of controlling site access from the LDAP directory service via role assignments. But, I am open to other ideas as well.
    Thank you!

    Hello,
    We have an Oracle 11g database with a table containing data from multiple sites (a SiteID field identifies the site for a record). Since application users can have access to different subsets of sites, we would like to use Oracle's Virtual Private Database feature to enforce row-level security on the table.
    I did a successful proof-of-concept with database users. I created a role for each site (example: USER_SITE_A, USER_SITE_B, ...), and then assigned the appropriate site roles to each database user. I then created a package (run via a logon trigger) which set application context attributes for each site. If the current database user has been assigned a role for a given site, then the corresponding attribute named "SITE_PRIVILEGE_SiteID" is set to 'Y'... otherwise, it is set to 'N'. Here is the code which worked to set application context attributes for database users:
    -- For each record in my RoleSitePrivileges table, set
    --   an attribute named 'SITE_PRIVILEGE_<SiteID>'.
    --   If the current user has been assigned a role matching
    --   the value in the 'RoleName' field, set the corresponding
    --   attribute to 'Y'... otherwise, set it to 'N'.
    FOR iPrivRec IN (SELECT RoleName, SiteID
                       FROM RoleSitePrivileges
                       ORDER BY SiteID)
       LOOP
          SELECT COUNT(*)
            INTO roleExists
            FROM dba_role_privs
            WHERE granted_role = UPPER(iPrivRec.RoleName)
              AND grantee = USER;
          IF roleExists > 0 THEN
             DBMS_SESSION.set_context(
                         namespace   => 'my_ctx',
                         attribute   => 'SITE_PRIVILEGE_' || iPrivRec.SiteID,
                         value       => 'Y');
          ELSE
             DBMS_SESSION.set_context(
                         namespace   => 'my_ctx',
                         attribute   => 'SITE_PRIVILEGE_' || iPrivRec.SiteID,
                         value       => 'N');
          END IF;
       END LOOP;To finish things off, I created a security policy function for the table which returns the following:
    RETURN 'SiteID IN (SELECT TO_NUMBER(SUBSTR(attribute, 15))
                         FROM session_context
                         WHERE attribute LIKE ''SITE_PRIVILEGE_%''
                            AND value = ''Y'')';This setup worked great for database users. I am now working to do a comparable proof-of-concept for enterprise users created in Oracle Internet Directory (OiD). I have Enterprise User Security (EUS) up and running with OiD, global roles created in the database, enterprise roles defined in EUS with global role assignments, and enterprise roles assigned to OiD users. The enterprise users are able to successfully login to the database, and I can see the appropriate global role assignments when I query the session_roles view.
    I tried using the same application context package, logon trigger, and security policy function with the enterprise users that I had used with the database users. Unfortunately, I found that the application context attributes are not being set correctly. As you can see from the code above, the applicaiton context package was referencing the dba_role_privs view. Apparently, although this view is populated for database users, it is not populated for enterprise users.
    I tried changing the application context package to use invoker's rights and to query the session_roles view instead of the dba_role_privs view. Although this package sets the attributes correctly when called manually, it does not work when called from the logon trigger. That was an oops on my part, as I didn't realize initially that a PL/SQL procedure cannot be called with invoker's rights from a trigger.
    So, I am now wondering, is there another view that I could use in code called from a logon trigger to access the roles assigned to the enterprise user ? If not, is there a better way for me to approach this problem? From a maintenance standpoint, I like the idea of controlling site access from the LDAP directory service via role assignments. But, I am open to other ideas as well.
    Thank you!

  • Is is better to use static variables?

    Hi,
    Does anyone know if it's better to use static variables or to use normal variables?
    Concerning the size of the code, it seems that declaring a variable as static is more consuming (for example plus 6 bytes for an object reference).
    So this could mean that declaring variables as static should be avoided, but what about the execution time?
    Some years ago, some javacard gurus were claiming that it's was better to use static variables (less processing required by the JVM to resolve adresses of static variables), but is it still the case?

    Hi Lexdabear,
    Thanks for the answer.
    I did the test (I converted my all code to use static variables and methods as much as possible), and did a bench before and after, on a JCOP31 card.
    The conclusion is that today JVMs and processors are much powerful than 5 years ago, and that the difference is really difficult to measure, which anyway is a good thing for us ;-)

  • I want to use static variable instead of using variable in servlet context

    Hi all,
    In my web application i have to generate a unique Id.
    For this, At the application startup time i am connecting to the database and getting the Id and placing it in the servlet context.
    Every time i am incrementing this id to generate a unique id.
    But, now i want to place this id in a static variable which is available to all the classes.
    why i want to do this is to reduce burden on servlet context.
    my questing is, is this a best practice ? If not please give me your valuable suggestion.
    thanks
    tiru

    There isn't a problem with this as long as you want to share the value of that variable with all requests. If this is read-only except when it is first set then you're fine. The only real issue will be how to initialize and/or reinitialize the variable. When the servlet is started, how will you get the value for the variable? If the servlet is shutdown and restarted (a possibility in any application server) how will you re-read the variable? You need to answer these questions to decide the best route. It may be as simple as a static initializer or it may be more complex like a synchronized method that is called to see if the variable is set.

  • Using a variable value in CDATA for generating an XML type in Oracle

    Hello,
    I have prepared a function given below where I have some input variables & I have to generate one XML with those input variables as tag attribute value:
    create or replace function NEW_PROJECT_DETAILS
    ( p_ReferenceId in varchar2 ,
    p_Project_No in varchar2,
    p_Project_Name in varchar2,
    p_Project_Desc in varchar2 ,
    p_Project_Type in varchar2,
    p_Project_Location in varchar2,
    p_Project_Status in varchar2 )
    return xmltype
    as
    payload xmltype;
    begin
    dbms_output.put_line('Payload Started');
    payload:= xmltype('<?xml version="1.0" encoding="UTF-8"?>
    <ProjectDetails>
    <RefID>'||p_ReferenceId||'</RefID>
    <ProjectNo>'||p_Project_No||'</ProjectNo>
    <ProjectName>'||p_Project_Name||'</ProjectName>
    <ProjectDesc>'||p_Project_Desc||'</ProjectDesc>
    <ProjectType>'||p_Project_Type||'</ProjectType>
    <ProjectLocation><![CDATA[p_Project_Location]]></ProjectLocation>
    /* <ProjectLocation>'||p_Project_Location||'</ProjectLocation> */
    <ProjectStatus>'||p_Project_Status||'</ProjectStatus>
    </ProjectDetails>');
    dbms_output.put_line('Payload Comp1');
    return payload;
    end;
    This procedure works absolutely fine.
    Now the problem which I am having is that the variable p_Project_Location has value like "6747:BBO&M SBV".
    Due to the '*&*' in that value I have to use CDATA. But i dont know how to pass this variable directly in the CDATA in the XML.
    Please help me with this asap.
    Thanks & Regards,
    Divya Aggarwal
    Edited by: 784414 on Dec 2, 2010 4:15 AM
    Edited by: 784414 on Dec 2, 2010 4:16 AM

    Hi,
    If you absolutely want to use a CDATA section, then :
    payload:= xmltype('<?xml version="1.0" encoding="UTF-8"?>
    <ProjectDetails>
    <RefID>'||p_ReferenceId||'</RefID>
    <ProjectNo>'||p_Project_No||'</ProjectNo>
    <ProjectName>'||p_Project_Name||'</ProjectName>
    <ProjectDesc>'||p_Project_Desc||'</ProjectDesc>
    <ProjectType>'||p_Project_Type||'</ProjectType>
    <ProjectLocation><![CDATA['||p_Project_Location||']]></ProjectLocation>
    <ProjectStatus>'||p_Project_Status||'</ProjectStatus>
    </ProjectDetails>');Alternatively, you can escape non valid characters with DBMS_XMLGEN.CONVERT, e.g. :
    payload:= xmltype('<?xml version="1.0" encoding="UTF-8"?>
    <ProjectDetails>
    <RefID>'||p_ReferenceId||'</RefID>
    <ProjectNo>'||p_Project_No||'</ProjectNo>
    <ProjectName>'||p_Project_Name||'</ProjectName>
    <ProjectDesc>'||p_Project_Desc||'</ProjectDesc>
    <ProjectType>'||p_Project_Type||'</ProjectType>
    <ProjectLocation>'||dbms_xmlgen.convert(p_Project_Location)||'</ProjectLocation>
    <ProjectStatus>'||p_Project_Status||'</ProjectStatus>
    </ProjectDetails>');which outputs :
    <?xml version="1.0" encoding="UTF-8"?>
    <ProjectDetails>
    <RefID>1</RefID>
    <ProjectNo>1</ProjectNo>
    <ProjectName>PRJ1</ProjectName>
    <ProjectDesc>This is project 1</ProjectDesc>
    <ProjectType>P</ProjectType>
    <ProjectLocation>6747:BBO&amp;M SBV</ProjectLocation>
    <ProjectStatus>S</ProjectStatus>
    </ProjectDetails>Any basic XML parser should then convert back escaped characters when processing the document.
    You can also use SQL/XML functions, which will take care of that automatically.
    For example :
    SELECT appendChildXML(
            XMLType('<?xml version="1.0" encoding="UTF-8"?><ProjectDetails/>'),
            XMLForest(
             '1'                 as "RefID",
             '1'                 as "ProjectNo",
             'PRJ1'              as "ProjectName",
             'This is project 1' as "ProjectDesc",
             'P'                 as "ProjectType",
             '6747:BBO&M SBV'    as "ProjectLocation",
             'S'                 as "ProjectStatus"
    FROM dual;or,
    SELECT appendChildXML(
            XMLType('<?xml version="1.0" encoding="UTF-8"?><ProjectDetails/>'),
            XMLForest(
             '1'                 as "RefID",
             '1'                 as "ProjectNo",
             'PRJ1'              as "ProjectName",
             'This is project 1' as "ProjectDesc",
             'P'                 as "ProjectType",
             XMLCData('6747:BBO&M SBV') as "ProjectLocation",
             'S'                 as "ProjectStatus"
    FROM dual;

  • "requires unreachable" warning emitted when using static variables and the singleton pattern

    I'm implementing code contracts on an existing code base and I've come across this situation in a few places. Wherever we have additional logic with code contracts where a singleton instance is instantiated, all code contracts emit a "reference use
    unreached", or "requires unreachable" warning.
    The code below demonstrates this.
    static string instance = null;
    static string InstanceGetter()
    if (instance == null)
    instance = "initialized";
    AdditionalLogic(instance); // requires unreachable warning on this line
    return instance;
    static void AdditionalLogic(string str)
    Contract.Requires(str != null);
    Console.WriteLine(str);

    Would the class get unloaded even if the Singleton object has some valid/reachable references pointing to it?
    On a different note, will all the objects/instances of a class get destroyed if the class gets unloaded.That's the other way round, really: instances cannot be garbage-collected as long as they are strongly reachable (at least one reference pointing to them), and classes cannot be unloaded as long as such an instance exists.
    To support tschodt's point, see the JVM specifications: http://java.sun.com/docs/books/jvms/second_edition/html/Concepts.doc.html#32202
    *2.17.8 Unloading of Classes and Interfaces*
    A class or interface may be unloaded if and only if its class loader is unreachable. The bootstrap class loader is always reachable; as a result, system classes may never be unloaded.
    Will the same case (Custom ClassLoader getting unloaded) occur if I write the singleton using the code wherein we lazily initialize the Singleton (and actually create a Singleton instance rather than it being a Class/static variable).You should check the meaning of this vocabulary ("object", "instance", "reference"): http://download.oracle.com/javase/tutorial/java/javaOO/summaryclasses.html
    The difference between the lazy vs eager initializations is the time when an instance is created. Once it is created, it will not be garbage collected as long as it is reachable.
    Now I'm wondering, whether being referenced by a static attribute of a class guarantees being reachabe. I'm afraid not (see the JLS definition of reachable: http://java.sun.com/docs/books/jls/third_edition/html/execution.html#44762). That is, again, unless the class has been loaded by the system class loader.

  • How to use Environment variables in Context Settings

    I need to set some Preferences using a Context, and in the value of the preference I need to use a path which may change depending on the OS.
    I need to use environment variables or java variables to create the relative path for the value.
    Is possible to access env variables from a Context Setting?
    Just to give an example, I'm trying to set the M2_REPO variable in the classpath settings in the preferences menu.
    to user.home + /.m2/repository
    How can I access the user.home from there?

    Hi Matias,
    Sure, you can use substitute-variables command for this purpose.
    See the example below:
    concat [substitute-variables "${system_property:user.home}" | str] "/.m2/repository"]
    Kind regards,
    Ulyana.

  • Thru code how to create a context node n context attribute for a table

    Hi Friends....i need some clarification...according to my requirement i need 2 create contx node n ctx attribute for a table..i.e through the code(implemention NWDS) means this has 2 b done in dynamically...
          More clearly according to the structure of a table in MySql DB the same table structure  has 2 b designe in my view ..suppose my table(MySql) have 20 col's(name,dept,desig..) n 300 recoreds ..i hav to show that structure in view.
    waiting for reply..frndzzzzzzzz

    Hi Rajeshkelam,
    Take a Value Node say "Employee".
    Create 20 Value attributes (name, dept, desig..) under the Value Node(Employee).
    Then Create a Dynamic Table using the "Employee" Value Node.
    check this threads.
    Dynamic table creation
    Dynamic Table
    Regards,
    Mithu

  • Using static variable in orchestration for each message

    Once a file is dropped to our Biztalk server I am capturing data from each message. However, I need to assign a batchID for this file that I will write to the database along with the data. How do I build my orchestration so that the code I'm using to generate
    the BatchID doesn't create a new ID for each message? I want each message to use the same ID.
    Thanks.
    Raymond

    Shankycheil,
    I think you've pointed out my primary issue. I'm fairly new to Biztalk and I just kind of let it do its thing when it comes to EDI processing. So, I guess my issue is due to the fact that I'm letting the EDI Disassembler debatch the file and pass messages
    into the orch one at a time. I have code in an expression shape that generates a BatchID, but of course if I'm debatching it creates a new BatchID for each message. How do I deal with the file as a whole inside the orchestration so that once I generate a BatchID
    it uses it for all of the messages in file? I've done what Prabhdeep suggested and promoted a field in the schema so that I can set the BatchID, but it needs to be the same for each message in a file.
    Thanks.
    Raymond

  • Using local variables or global attributes

    it's been five years now since I learned programming.
    But I still have a pretty basic question that isn't answerred yet ...
    I'll try to explain it with an example
         //*attributes*
         private int a, b, c;
         private int result
         a =1;
         b =2;
         c=3;
         //first option
         calculate1();
         System.out.println("the result is : " + result);
         //second option
         calculate2(a,b,c);
         System.out.println("the result is : " + result);
         //third option
         result = calculate3();
         System.out.println("the result is : " + result);
         //fourth option
         result = calculate4(a,b,c);
         System.out.println("the result is : " + result);
         private void calculate1(){
              result = a+b+c;
         private void calculate2(int a, int b, int c){
              result = a + b + c;
         private int calculate3(){
              return a+b+c;
         private int calculate4(int a, int b, int c){
              return a+ b + c;
         }what's the best, and why?

    Regarding performance:
    I tested your example with the code below. I run every test case 10 times: These are the results:
    calculate1 = 7567 ms
    calculate2 = 8046 ms
    calculate3 = 7609 ms
    calculate4 = 8047 ms
    So, the variants with method parameters are slower. That&#8217;s clear, because we have to push and pop the variables to/from stack. I think the &#8216;huge&#8217; difference between calculate1 and calculate2 results from the unpurified test (Garbage Collector activities, System activities, &#8230;).
    Regarding style:
    It&#8217;s up to you, if you like to use your attributes directly or method parameters. That&#8217;s OOP :)
    As far as I&#8217;m concerned:
    Your attributes are private. So, within an object I would try to use the attributes directly as often as possible. That&#8217;s the reason why I would use calculate1.
    Cheers,
    Chris
    public class TestMe {
         private int a = 1, b = 2, c = 3;
         private int result;
         private int n = 1000000000;
         public void testCalculate1() {
              long t0 = System.currentTimeMillis();
              for (int i = 0; i < n; i++) {
                   calculate1();
              long t1 = System.currentTimeMillis();
              System.out.println((t1 - t0));
         public void testCalculate2() {
              long t0 = System.currentTimeMillis();
              for (int i = 0; i < n; i++) {
                   calculate2(a, b, c);
              long t1 = System.currentTimeMillis();
              System.out.println(t1 - t0);
         public void testCalculate3() {
              long t0 = System.currentTimeMillis();
              for (int i = 0; i < n; i++) {
                   result = calculate3();
              long t1 = System.currentTimeMillis();
              System.out.println(t1 - t0);
         public void testCalculate4() {
              long t0 = System.currentTimeMillis();
              for (int i = 0; i < n; i++) {
                   result = calculate4(a, b, c);
              long t1 = System.currentTimeMillis();
              System.out.println(t1 - t0);
         private void calculate1() {
              result = a + b + c;
         private void calculate2(int a, int b, int c) {
              result = a + b + c;
         private int calculate3() {
              return a + b + c;
         private int calculate4(int a, int b, int c) {
              return a + b + c;
         public static void main(String args[]) {
              TestMe t = new TestMe();
              // t.testCalculateX();
    }

  • Using static variables in ejb

    I'm interested in the rule from the EJB spec:
    � An enterprise bean must not use read/write static fields. Using read-only static fields is
    allowed. Therefore, it is recommended that all static fields in the enterprise bean class be
    declared as final.
    This rule is required to ensure consistent runtime semantics because while some EJB containers may
    use a single JVM to execute all enterprise bean�s instances, others may distribute the instances across
    multiple JVMs.
    question 1
    Can you call "Math.random();" in ejb code???
    The javadoc for this method says
    When this method is first called, it creates a single new
    * pseudorandom-number generator
    This means that you can't use it right?
    This is not a problem for me, I know that you can go (new Random()).nextDouble();
    What I'm interested in is, does the EJB spec permit use of this method, and how are you supposed to know when you're breaking the spec like this.
    question 2:
    how about if you have a class
    class MyClass{
    public static final ArrayList MY_LIST = new Arraylist();
    Surely you can't read and write to MY_LIST from EJB's cause you're breaking the rule.
    But at what point are you actually breaking the rule?
    Can anyone out there spell this out for me??

    � An enterprise bean must not use read/write static fields. Using read-only static fields is
    allowed. Therefore, it is recommended that all static fields in the enterprise bean class be
    declared as final.
    Note that the rule covers usage of ALL static fields, not just fields on the implementation class.
    If I use
    MYBeanStaticVariableHolder.myStaticVariable
    for read/write.
    I understand that it's not a good idea, and I would never do it.
    But, does it actually break the spec. yes or no!!! - YES
    If yes, then fine I'm happy, what about my Math.random() question?
    Can you call "Math.random();" in ejb code???
    Math.random() is effectively read-only, because you never write to the result returned and therefore does not break the rule, so calling Math.random() would be allowed.
    how about if you have a class
    class MyClass{
    public static final ArrayList MY_LIST = new Arraylist();
    Surely you can't read and write to MY_LIST from EJB's cause you're breaking the rule.
    But at what point are you actually breaking the rule?
    Can anyone out there spell this out for me??
    If you write to a static field, update the state of an object in a static field, or update the state of an object returned by a static method, when the method does not return a unique instance at each invocation, you are breaking the spec
    public class Sample
        public static final int START_MODE = 0;    // OK
        public static final int STOP_MODE = 1;      // OK
        public static int DEFAULT_MODE;           // updating this is BAD
        private int currentMode;
        public int getMode(){ return currentMode; }
        public void setMode(int mode){ currentMode = mode; }
        // Updating instance is BAD
        public static Sample instance = null;
        // Updating returned instance is BAD
        public synchronized static getInstance()
            if( instance == null ) instance = new Sample();
            return instance;
        // Updating returned instance is OK
        public synchronized static getUniqueInstance()
            Sample instance = new Sample();
            instance.setMode(Sample.MODE_START);
            return new Sample();
    }Hope that helps.

  • How to use local variables in control files for loading data

    i want to count the number of records which have odd number like...
    Data in data.txt
    1 a
    2 b
    3 c
    So my count = 2, i will write this to another file.
    Plz help me how to achieve this

    If you want to extract some rows from a file and write them to another one, why do you need Oracle? What is your requirement?
    Or are you asking out of curiosity how can this be done in Oracle?
    You can create an external table for this input file, select the rows you want from it and write them to another file using utl_file.
    External tables: http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/et_concepts.htm#SUTIL011
    UTL_FILE: http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/u_file.htm#sthref14095

  • Using static variables in JSP

    Hi All,
    I have written the following code, but its not compiling saying that "Class or interface declaration expected. static "
    I dotn know whats wrong in this scriplet though.. any help is greatly appretiated.
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>JSP Scriplet</title>
    </head>
    <body>
    <%
    static int counter = 15;
    for(int i = 0; i < 15; i++){
    int p = returnCounter();
    if(p == 0)
    System.out.println("I am the 15th user");
    public static int returnCounter(){
    counter = counter - 1;
    System.out.println("counter : " + counter);
    return counter;
    %>
    </body>
    </html>

    Simply put, you're Java code is wrong.
    The detail is that essentially all of the code in your JSP file is in one big method.
    So, here's what your code looks like to the compiler:
    public void _internalJspDoPageCode() {
        static int counter = 15;
        public static int returnCounter() {
    }You can't simply nest methods like this in Java.
    If you want to, you can try this:
    <%
        public class mycounter {
            static int counter = 15;
            public static int returnCounter() {
                counter = counter - 1;
                return counter;
        for (int i = 0; i < 15; i++) {
            int p = mycounter.returnCounter();
            if(p == 0)
                System.out.println("I am the 15th user");
    %>That will create an inner class with a static member, which is basically what you're trying to do.
    But note that this inner class is only accessible from this JSP page, and no where else.

Maybe you are looking for

  • Exchange AutoDiscover not working correctly in 2010/2013 environment

    Here's my setup: Mixed environment transitioning: Exchange 2010 running on Server 2008 in a VM Exchange 2013 running on Server 2012 in a VM I have split dns so that autodiscover.domain.com points to my 2013 server internally and my 2010 server extern

  • Attaching a word document to the work item

    Hello Everyone,                           I want to send an attachment with the work item. My requirement is as follows. Iam working on CRM.  The Business Object which Iam using is BUS2000116. In this Activity, there is an attacment tab. Here the use

  • Safari won't display online banking login - ipad mini

    Hi, my ipad mini has stopped displaying my online banking login page in safari. It is ok when using iPhone 4S and ipad. Have not got any idea as to why but it is driving me NUTS! Please can someone help?

  • Null data in the flat file

    HI , i have generated a flat file after extracting data from oracle database. my table has 10 fields and out of which second and third fields are null.. But after populating the data in the file, i could not see the empty spaces for those fields, the

  • Disk Space "leaking" in Java Application Using java.io.RandomAccessFile

    I have noted this behaviour in both java version 1.2.1 and 1.3.1 on Solaris 5.8. I have a java application that is essentially "tailing" a very large log file. The program opens a RandomAccessFile in read-only mode and calls readLine on the file as l