About visibility of variables in concurrency

Hi,
I have a class that implements Runnable, and it has a constructor. As we know to ensure the change visibility of variables in different threads we need to use the "volatile" key word.
So if I do not use "volatile," and contruct the object in the main thread, and then access and modify them in the run() method, could there be any problem? (after construction the run() method is the only place these variables are accessed and modified)
Thanks!

808239 wrote:
Hi,
I have a class that implements Runnable, and it has a constructor. As we know to ensure the change visibility of variables in different threads we need to use the "volatile" key word.
Not true.
First, variables' visibility is unaffected by multithreading. Presumably you're talking about the variables' values.
Second, volatile is not the only way. Making sure all access to those variables occurs in synchronized blocks or methods also ensure that threads see each others' updates. Or you could use the classes in java.until.concurrent.atomic. Which one is appropriate depends on your particular needs, of course.
So if I do not use "volatile," and contruct the object in the main thread, and then access and modify them in the run() method, could there be any problem? (after construction the run() method is the only place these variables are accessed and modified)If there's a shared variable, and you don't mark it volatile or sync all access to it, then, yes, you don't know when or even if one thread will see another thread's write of that variable.
However, it sounds like you're saying only one thread is even using these variables. If so, this is not an issue. If you're worried about a child thread seeing the values that the parent set before start()ing the child, it's not a problem. Writes that occur before starting a thread have a "happens-before" relationship with all accesses in that new thread.
Edited by: jverd on Mar 9, 2011 2:36 AM

Similar Messages

  • Question about using constant variables in Forms

    As I am still very new to Forms, please forgive my ignorance if the answer to my question is very simple. I am trying to figure out how to use constant variables within my Forms application. For example, if I want to setup return code constants for the application (mind me, these are examples):
    RC_SUCCESS CONSTANT PLS_INTEGER := 1;
    RC_FAILURE CONSTANT PLS_INTEGER := 0;
    RC_YEAR_DATA_NOT_FOUND := 50;
    Then in a module I created, if I wanted to check the return code against one of the constants I would do:
    DECLARE
    rc PLS_INTEGER;
    BEGIN
    GET_YEAR_DATA('2000', rc);
    IF rc = RC_YEAR_DATA_NOT_FOUND THEN
    -- Do some error handling
    END IF;
    END;
    I know that you can declare constants within individual procedures or packages but I can't see to find information on how to do this globally for the application. I've read about using global variables within Forms but the CHAR data type only and the fact the value can be changed doesn't really fit for this purpose. Am I missing something? Is there a config file or something for the webserver that can be used to set these up??
    Any help would be appreciated.
    Thanks

    To declare constants create a Package-Specification in a pll and deifne all your constants there, something like:
    PACKAGE PK_CONSTANTS IS
      RC_SUCCESS CONSTANT PLS_INTEGER := 1;
      RC_FAILURE CONSTANT PLS_INTEGER := 0;
      RC_YEAR_DATA_NOT_FOUND := 50;
    END;Then attach that pll to all your forms-modules, and use it like
    IF rc = PK_CONSTANTS.RC_YEAR_DATA_NOT_FOUND THEN
    END IF;A word about exceptions or errors: In my eyes its clearer (and in case of exceptions even better) to raise an exception than to hide it behind return-codes.

  • Visibility of variables in a multithreaded application

    In a code review of our GUI application, we encountered some multithreading problems, concerning the visibility of variable values.
    In theory, write and read operations have to be synchronized or at least, volatile has to be used to provide a accurate access to the variable values from different threads.
    Although we have encountered many code sequences in our application violating the above rules, we have never seen a problem in our application.
    This forced us to write a simple test program which should discover these problems, but there was no difference using volatile or non volatile variables !!
    Our experience is, that on our platform (Intel Core2Duo/Pentium M - Linux 2.6.23 - Sun Java HotSpot 1.6.0_04), no visibility problems caused by multithread access occurs, even if the variables are neither declared as volatile nor protected by a synchronized block.
    Is there anybody out there, who has more details to this multi threading issue ?

    Pulsar7 wrote:
    But visibility of variables in multi core environments is not an issue of atomic access.No. I meant to say that you also can see other problems if you remove the syncronized/volatile access. Reading stale data isn't the only problem.
    Multi-Core architectures can have per core-registers, -caches, -controller devices interchanging the memory content in a certain way.
    It is obvious, that two thread running on different cores should run into problems. But we do not see them !?It's all implementation and hardware dependent. You can get different result when you are executing on different VMs as well as different operating systems.
    Are there some memory consistency features implemented in modern CPUs, supporting immediate register/cache/memory updates ?
    Is the behaviour depended on the OS ?See above.

  • Jdev11 complains about public instance variables, but not Jdev10

    Hi all, if I fire up Jdeveloper10 I can declare a public instance variable. (OK, stylistically maybe not a good thing, but nothing in the java 'rules' that says I shouldn't be able to do this.) However in Jdeveloper11 it complains, it underlines it in red and grumbles "should not have greater than protected access."
    Anyone know where to turn off this compiler hint?
    thanks.
    public class Thing() {
    public String bob; // complains in jdev11, ok in jdev10.

    Hi Kevin, thanks for the tip. It's taken me years just to remember where to turn on the line numbers in 'preferences' , so I would never have found that one about the instance variable checks ! Frank, thanks for the update, I agree it's useful as a stylistic hint, but I think that the Jdev floating code assist, rather than just hinting "declare this field protected" (as this will obviously fix it) would be more user-friendly if it also said "or disable under preferences - code assists." But Jdev11 is growing on me, tons of cool stuff :-)
    thanks all.

  • Variable is not visible at variable sequence in BEX

    Hi Experts,
    I have created the new query with selection variables in BEX (BI 7). Now I want to change the sequence of the variable selection. But there are no variables at variable sequence in query property. Please any suggestions.
    Thanks In Advance
    Ravi

    Dear Ravi,
    while defining a variable,,
    u have an option like READY FOR INPUT.
    u should tick that check box..
    unless and until u check that box,,..that variable will not pop up or visible in the query designer..
    Hope this helps u.
    Best Regards,
    VVenkat..

  • Difference between volatile and atomic variables (util.concurrent.atomic)

    All,
    Can some one explain to me the difference between using
    volatile variables and atomic variables as incremental/decremental counters
    that is shared by multiple threads.
    when should I use volatile and when should I use atomic variables.

    angeshwar wrote:
    All,
    Can some one explain to me the difference between using
    volatile variables and atomic variables as incremental/decremental counters
    that is shared by multiple threads.
    when should I use volatile and when should I use atomic variables.
    x++ is not atomic for a volatile variable. You can have ten threads executing that concurrently and only get a increment of one when it should have been ten. This problem won't happen with AtomicWhatever.

  • Who can tell me the details about "JMSJVMOPTS" environment variable of JMSC API

              I have a question about JMS C API.
              When in windows service application, JMSContectCreate return JMS_JVM_ERROR error.
              But in desktop app, it does well.
              I think I may need set the JMSJVMOPTS environment variable.
              But how to set JMSJVMOPTS ?
              

    OK,
              The JMSJVMOPTS are extra options passed to the "java" executable itself
              along with
              "-Djava.class.path=${CLASSPATH}"
              Hence, the actual things you can set with this depend on which java compiler
              you are using. If you are using the Sun JVM for instance, here are some of
              the options you can set (from java -?)
              where options include:
              -client to select the "client" VM
              -server to select the "server" VM
              -hotspot is a synonym for the "client" VM [deprecated]
              The default VM is client.
              -cp -classpath <directories and zip/jar files separated by ;>
              set search path for application classes and resources
              -D<name>=<value>
              set a system property
              -verbose[:class|gc|jni]
              enable verbose output
              -version print product version and exit
              -showversion print product version and continue
              -? -help print this help message
              -X print help on non-standard options
              -ea[:<packagename>...|:<classname>]
              -enableassertions[:<packagename>...|:<classname>]
              enable assertions
              -da[:<packagename>...|:<classname>]
              -disableassertions[:<packagename>...|:<classname>]
              disable assertions
              -esa | -enablesystemassertions
              enable system assertions
              -dsa | -disablesystemassertions
              disable system assertions
              As far as what sort of things can cause a JMS_JVM_ERROR from
              JmsContextCreate the answer is that there are many, many reasons this might
              be happening. Please look for a file named ULOG.<mmddyy> (where mmddyy is
              month/day/year - for example ULOG.081403) somewhere on your system (I am not
              sure where this file would go being run from a W2K service). That "userlog"
              file should contain more information about why the failure occurred.
              Also, you can set JMSDEBUG=y in your environment which will print to stdout
              (again, not sure where stdout goes in a system service) stack traces and
              other debugging information into the ULOG file.
              Hope this helps...
              "Luke" <[email protected]> wrote in message
              news:[email protected]...
              >
              > Hi,John Wells,
              > thanks for your help.
              > But what I really don't know is what value I can set for JMSJVMOPTS.
              > There is not document about the detail of optional values for JMSJVMOPTS.
              > And what reasons can result a JMS_JVM_ERROR in JmsContextCreate() ?
              

  • Hi experts i would like to know about user exit variables?

    Hi there experts,
            sorry for being pain, can some one give me an idea about what are user exit variables and where are they used ?cheers thanks.

    Hi,
    1)for example user when ever executes his report he wants only for current date by default
    then u create the user exit variable on 0calday example as 'zcedate'
    then go to the tcode CMOD here create the project then go to the Exit_saplrrso_001
    here u can insert the code like as below
    when 'zcedate'.
    clear l_s_range.
    l_s_range-sign = 'i'.
    l_s_range-option = 'eq'.(if it is between two dates then l_s_range-option = 'bt')
    l_s_range-low = sy-datum(if it is range l_s_range-low  = 'may be any date  or by using sy-datum - ) 
    append l_s_range to e_t_range.
    like this we can start and write for month to date and week to date by using the FM week_get_first_day and dat_get week
    and for year to date by using the FM first_and_last_day_in_year_get
    if u have any detailed  pls ince again tell me which are things u required.
    thanks for giving this oppourtinity.
    Thanks & Regards,
    k.sathish

  • Question about Hyperion Environmental Variables

    Hi,
    Can someone please give me a clear explanation about the following Environment variables in Hyperion. I am very much confused about these variables, it would be really helpful for me to understand better if I get a clear explanations of those.
    1) ARBORPATH
    2) ESSBASEPATH
    3) HYPERION_HOME
    4) ORACLE_HOME
    5)ORACLE_INSTANCE
    Thanks in advance!!!
    Regards,
    Newton

    Basically I want to know if declaring
    a final instance variable and assigning it to an
    existing Object will make an immutable copy of that
    Object. Big no. It will neither make a copy, nor will anything be immutable. Final just means that once the value or reference of the attribute or variable is set, it can't be altered.
    final StringBuffer sb = new StringBuffer();
    sb.append("!");still works.
    Your inner class will access the instance of Dimensions stored in myDims. There won't be any other instance.

  • Display variable for concurrent manager

    Hi,
    DISPLAY variable is wrong for Concurrent manager. We see it in the result of Generate Concurrent Processing
    Environment Information. We should set it in $APPLFENV file but we have several files for $APPLFENV :
    /Data/oracle/d01/mydb/9.2.0/appsutil/out/my_mysystem/09012005/my_mysystem.env
    /Data/oracle/d01/mydb/9.2.0/my_mysystem.env
    /Data/oracle/d01/myappl/my_mysystem.env
    /Data/oracle/d01/myora/iAS/my_mysystem.env
    /Data/oracle/d01/myora/8.0.6/my_mysystem.env
    In which one should I SET it ?
    Thanks and regards.

    user522961 wrote:
    But Display variable is always the ancient (the bad one). Is there any other env file to mofify ?In the application context file, set the environment variable "s_display" and run AutoConfig. This should set the DISPLAY in the env files as well as the startup/shutdown scripts (The DISPLAY should be set in the applmgr user profile, the env files, and the CM "adcmct.sh" script).

  • About "method", "instance variable" and "constructor"

    Does a method need to be initialise?? if yes, how to write the code?
    for example,is it:
    public String mymethod( String args[]); ?
    public double mymethod2 (); ?
    what is the meaning of "instance variable" and "constructor"?
    Please help.....THANKS!

    Previously posted to this OP:
    Read the Java Tutorial: Learning the Java Language.
    http://java.sun.com/docs/books/tutorial/java/index.html
    � {�                                                                                                                                                                                                                                                                                                   

  • Basic questions about Objects and variables...

    If I have the following:
    Species theAnimal = new Species();
    Am I right in saying that the object here is 'theAnimal'?.
    If we just wrote it as:
    Species theAnimal
    Then i'm assuming that here 'theAnimal' is the variable name...right?
    I'm just trying to get facts straight when reading.
    Thanks for the help...
    Yash

    At first, theAnimal is pointing to one object, and
    theMammoth is pointing to another?
    In the final line, they're both pointing to the same
    object. Isn't that kind of saying, they're pointing
    to the same memory address/location?Yes.
    They might actually hold the physical memory address of the object, or they might hold some other abstraction that the VM uses to locate the object. In either case, though, they both hold the same value, and you can picture that value as the address of the object.

  • About package global variable.

    Hi All,
    Could you please anyone tell me from which Data Dictionary tables we can find to definiton of Package global variables which is declared in specification part.
    I tried in ALL_ARGUMENTS but I failed to get it.
    Thanks in advance.

    Thanks James for you reply.
    We written an application using utPLSQL framework, which is used to write unit test cases for Oralce server side programs.
    In one of our Oracle package we have been using global variable and is been referred by all the public members.
    To initailize the package global variable based on our test case we need to know the package global variables.

  • Question about Visited slide variables

    Hi All,
    I have seen an effect in a scorm course that I would like to replicate, unfortunatly it was not in Captivate.
    I would like a button to contain a table of contents to appear when you hover over a button/image. Next to the title of the slide I would like a tick to show if the user has visited the slide or not.
    There are 20 slides in my module and to represent this I would like 20 small squares at the bottom of each slide. Is it possible for them each to be a button that a) takes user to corresponding slide, b) Is red if it is the slide they are looking at, and c) Is blue if they have visited it as now they can technically jump to any slide.
    Thanks in advance everybody.
    Chris

    Hi Chris
    Aside from using the Table Of Contents (TOC) feature, Captivate doesn't really offer anything like this.
    If you want to be adventurous, you could construct something like that using images and variables and Advanced Actions to hide and show the images.
    Cheers... Rick
    Helpful and Handy Links
    Captivate Wish Form/Bug Reporting Form
    Adobe Certified Captivate Training
    SorcerStone Blog
    Captivate eBooks

  • Question about final instance variables

    Hi, I recently have come across a situation that I realized I did not understand and I could not find the answer after a bit of googling and searching the forum so I thought I would quickly pose the question to the crowd. Basically I want to know if declaring a final instance variable and assigning it to an existing Object will make an immutable copy of that Object. For example:
    Dimension myDims;
    public void someMethod()
    myDims = new Dimension(320, 240);
    doSomething();
    public void doSomething()
    final myFinalDims = myDims;
    This is not real code (obviously) and I made it quickly just to get my point across. Basically my question is if I create an Anonymous Inner class within the doSomething() method that accesses the myFinalDims variable, will the inner class actually access the myDims variable (which could have its value changed before the inner class accesses the variable) or will it be accessing a copy of the myDims Object that will have the same value as when the final variable was declared and instantiated?

    Basically I want to know if declaring
    a final instance variable and assigning it to an
    existing Object will make an immutable copy of that
    Object. Big no. It will neither make a copy, nor will anything be immutable. Final just means that once the value or reference of the attribute or variable is set, it can't be altered.
    final StringBuffer sb = new StringBuffer();
    sb.append("!");still works.
    Your inner class will access the instance of Dimensions stored in myDims. There won't be any other instance.

Maybe you are looking for

  • Problem with InternalFrame. Help!!

    hai, I am having two classes of internalframes. I want to open 'IFrame1',first internalframe by giving command. It is coming correctly. After 'IFrame1' is opened, if anyone presses 'IFrame2' button, internalframe2 should be opened. It is opening corr

  • Installing Functional Module as a Customer Extension

    Hi All, Am not a Basis guy and have stuck up in a issue at customer place. I need to import, install and activate function module as transport into the R/3 system. In Note # 1050096, there is a attachment with two files K900947.SM0 R900947.SM0 I need

  • Mavericks and pages '09 (4.3)

    I upgraded to Mavericks and when completed first of all checked several book files all created in pages Text in these books had been created with the font Garamond - but something has happened and the font is completely different almost elongated com

  • ICloud Control Panel does not sync more than 139 Images

    Hello Forks, i'm encountering a Problem with iCloud Control Panel v 3.1 running on Windows 8.1 Professional on a Lenovo Think-Tablet. When I enable Photostream it downloads excatly 139 Images and stops after that. On my Windows 8(.0) Laptop and my ma

  • Various Installers and Utilities Freeze (Won't Load)

    When I try to run software update, disk utility, printer setup utility, etc., they all freeze after trying to start. Also, firefox and adobe acrobat have been freezing peroidically. Other software runs fine, such as Entourage, Quark or Photoshop. Thi