How to access static variable from a Thread class

Kindly help me.......
here's the code.....
class Thread1 extends Thread
int j=0;
myClass2 mc = new myClass2();
     public void run()
          for( int a=0;a<6;a++)
                    {try
                         { Thread.sleep(5000);
                         catch(Exception e){System.out.println("Interrupted Exception");}
                         j++;
mc.change1(i);
} System.out.println("Thread1 executes "+j+" times");
class Thread2 extends Thread
int k=0;
     myClass2 mc1 = new myClass2();
     public void run()
          for( int a=0;a<6;a++)
                    {try
                         { Thread.sleep(5000);
                         catch(Exception e){System.out.println("Interrupted Exception");}
                         k++;
mc1.change2(i);
}System.out.println("Thread2 executes "+k+" times");
class myClass2
static int i=5;
public synchronized void change1(int s)
s=6;
System.out.println("New value of i:"+s);
public synchronized void change2(int s)
s=7;
System.out.println("New value of i:"+s);
     public static void main(String args[])
Thread1 b1 = new Thread1();
Thread2 b2 = new Thread2();
     b1.start();
b2.start();
I am unable to pass the variable i in my method call in Thread1: mc.change1(i); and similarly in Thread2:mc.change2(i);

You can declare your i variable in myClass2 as public static and then simply call there
    mc.change1( myClass2.i ) ;

Similar Messages

  • How to access a variable from within a symbol.

    How do I access a variable set outside a symbol from within that symbol?
    Thanks

    If you set a variable on stage ,say
    sym.setVariable("stageVariable", "I am stage variable");
    You can access it from within  a symbol using :
    var myVariable = sym.getComposition().getStage().getVariable("stageVariable");
    Basically you need to get handle to the symbol in which the variable is defined.

  • How to access a variable from one program to another (independent)

    Hi,
    My requirement is to use a variable(value) from one program(prog1) to another (prog2). how is it possible.
    Regards
    Arani Bhaskar

    Go for memory id .
    passing on values from one program to another program
    Program1
    EXPORT (variable) TO MEMORY ID 'LOC'.
    Program2
    IMPORT (variable) FROM MEMORY ID 'LOC'.
    LOC is the address , for more press f1 on export in abap editor.

  • Accessing static variable from subclass

    Hi,
    this question is probably fairly common but I can't seem to find the answer around: Can somebody please explain the rationale behind the following behavior ?
    public abstract class SuperClass {
        static String mess;
    public class SubClass extends SuperClass {
        static {
            mess = "Hello world!";
        static String getMess() {
            return mess;
    public class mymain {
        public static final void main(String[] args) {
            System.out.println(SubClass.getMess());
    }gives "Hello world!" as expected whereas
    public abstract class SuperClass {
        static String mess;
        static String getMess() {
            return mess;
    public class SubClass extends SuperClass {
        static {
            mess = "Hello world!";
    public class mymain {
        public static final void main(String[] args) {
            System.out.println(SubClass.getMess());
    }gives "null". It looks like the initialization block is not executed. Why?
    Thanks for your insight,
    Chris

    >
    You're essentially claiming you need to override some static methods.No, there is indeed misunderstanding here. What I need to do is implement the methods with the signature given, I'm not overriding existing methods, in fact I'm not even deriving from any existing class. I only have to create the entry points in my code as defined, then publish them to the DB, and Oracle is going to use them (I think they can be called callbacks, also again not 100% sure).
    Then it happens that in my particular case it's natural to have a master containing all the code and then subclasses that only define a few specific parameters that are to be used by the static (and instance) methods. Hence the final design. Currently my code looks like the following and seems to work (fingers crossed):
    class ParseFileCLL extends ParseFile {
        // Name of the row type.
        private final static String rowType = "CLLROW";
        // Here I initialize static fields of the ParseFile master class.
        static {
            fileType = "CLL";
            fileStruct = new FileStruct(34);
        // Type methods implementing ODCITable interface.
        static public BigDecimal ODCITablePrepare(STRUCT[] sctx, STRUCT tfinfo, String sysName)
                throws SQLException {
            // prepareContext is a static helper method defined in the master class.
            return prepareContext(funcType, rowType, rowSetType, tfinfo);
    // Other ODCI methods are only accessed directly in the master class, NOT in the subclass. Or else... WEIRD BUGS!
    // In other words:
    //  publish ParseFile.ODCITableStart() -> ok
    //  publish ParseFileCLL.ODCITableStart() -> crash
    }Not surprising. Java has plenty of undefined or inconsistently-defined behavior. The JLS is by no means perfect.
    >
    Well I kind of admire your composure about this, but it seems to me that if it's indeed the case, the meaning of it would be that the code could work in JVM 1.5.0.15 and not in 1.5.0.16, or worse run ok on Windows and not on Linux, which is if I understand correctly precisely the kind of behavior that Java was meant to cure, at least at its inception.
    I think there might be other elements to the story though.
    Thanks,
    Chris

  • How to access environment variables from Oracle Forms

    Hi,
    Any idea how to use the Environment variables from Oracle Forms.
    My basic problem is that from Oracle form I am calling Batch file which calls excel file with a macro.
    So i want to check whether the macro was successful or not.
    So in my batch file i will set %errorlevel% which I should be able to read from Oracle Forms.
    I am able to read the registry from oracle forms, so is there anyway to read environment variable as well?
    Thanks!
    Avinash.

    Hello,
    Use the TOOL_ENV.Getvar() built-in
    Francois

  • How to access environment variables from pluggable destination?

    Hi,
    I'm trying to create a java puggable destination for reports. Everything is working fine.
    I want to access reports environment variables from the java code (like REPORTS_PATH and other new variables that I want to create), but I can't find anything about this in the java API documentation.
    I want to use environment variables instead of destination properties (those I can easily access), because I want to be able to change context using env_id.
    Any ideas?
    Thanks,
    Luis

    I'm using Oracle Application Server Version 10.1.2.0.2
    Thanks

  • Accessing String variables from several JAVA classes

    Hi.
    I have several java classes that accesses the same String variables. Instead of putting the String declarations in every java files, how can I put these declarations in a single file source, and get each java class to get the variables data from this file ?
    Please advice.
    Thanks.

    hi, of course you can solve it by the following methods:
    Method 1. define a superclass including the common string variable, and extend other classes from the superclass.
    Method 2. define a class , and define your common string variable as a static variable in it. In your other classes, you can call the string variable.
    Method 3. define it at your each classes.

  • How to access a variable from a dynamically included JSP page

    I have a jsp (say main.jsp) using the following in its code :
    <jsp:include page="menu.jsp" flush="true" />
    I have a variable in menu.jsp which I would like to use in my main.jsp.
    How do I get the value of the variable defined in menu.jsp ?
    I called this variable in menu.jsp, Public, but this didnot help me use the value of that variable in main.jsp
    Any help is highly appreciated.. thnks a lot

    I do notice the variable var1 has the value populated - in menu.jsp - (from View -->
    Source in the browser) but for some reason not able to use it in main.jspI'm not quite sure of the way your jsps are structured from your code snippet but I think there is something to be aware of here that may be part of your problem, namely the difference between the include directive and the include action.
    You are currently using the include action, this treats the included resource as a dynamic object - i.e. a request is sent to that resource and the resulting response is included in your page. So when you think of what there is no java variable actually included - you'll just get the resulting HTML that is generated by menu.jsp
    The include directive, as in <%@include file=�menu.jsp � %>, on the other hand treats the resource as a static object. This means the actual bytes in the included resource are inserted into the including jsp and then the result of that is compiled and processed, effectively you are cutting and pasting the menu.jsp into your calling jsp. In this case the variable would be available to the calling jsp.
    However this approach does bring other difficulties that may break your current code, you'll just have to try it and see what happens.
    Hope that's relevant to your problem,
    Matt

  • How to access (call) variables from multiple components

    I have what I think is a basic task, but I cant seem to get it to work.  I have a Flex project with one application.  In addition to the one application, I have many components that are used in the application.  These components vary from simple (a ComboBox) to complex (many sub-components).  What I need to do is define a viable in one component and access it in another component.  I can't seem to do this.  Below is an example of how I think it should be:
    Component1
    <mx:Script>
           <![CDATA[
            [Bindable]
            private var userID:int=0;
           ]]>
    </mx:Script>
    Component2
    <mx:TextInput  text="{Component1.userID}"/>
    Any help you can provide would be beneficial.
    Lee

    Hello,
         You may also want to consider using the mx.core method.
         In your main application script area define all of your public variables and functions. Then from your component, you can reference these absolutely with the following syntax.
    <!-- Main App -->
    [Bindable]
    public var userID:int;
    <!-- Component -->
    private function init():void {
         var com_UserID = mx.core.Application.application.userID;
    Using this method ensures that you will have access to any Function or variable within the scope of the project.
    Kind Regards,
    Dr. Ivan Alexander, Ph.D.
    Sr. Applications Engineer
    FlexAppsStore.com
    Sun Microsystems
    MySQL Enterprise Ready Partner 2009

  • How to access workflow variables from business classes?

    In WLI2.1 the com.bea.wlpi.server.admin.Admin bean was useful to retrieve workflow
    variables for a particular instance id.
    Is there anything similar in 8.1?
    We have to do the following:
    In the workflow, when a particular task gets created, a user (claimant of the
    task) should be able to pull the workflow xml data in a JSP. The user may update
    the data from the JSP and then the updated xml needs to be saved in the workflow.
    Then, onTaskCompleted, the updated xml will follow the rest of the workflow.
    How to do this is 8.1?
    Thanks in advance.

    Hi,
    Pls check for setRequest/setResponse in task control and setTasksRequest/setTasksResponse
    i task worker control. Hope this will resolve your issues as they have XmlObject
    as parameter.
    Regards
    Sai
    "Aparna" <[email protected]> wrote:
    >
    In WLI2.1 the com.bea.wlpi.server.admin.Admin bean was useful to retrieve
    workflow
    variables for a particular instance id.
    Is there anything similar in 8.1?
    We have to do the following:
    In the workflow, when a particular task gets created, a user (claimant
    of the
    task) should be able to pull the workflow xml data in a JSP. The user
    may update
    the data from the JSP and then the updated xml needs to be saved in the
    workflow.
    Then, onTaskCompleted, the updated xml will follow the rest of the workflow.
    How to do this is 8.1?
    Thanks in advance.

  • How to access a variable from inside another symbol

    So i did this tutorial, Leveraging Independent Symbol Timelines created by Eliane...it's rockin, btw.  ;-)
    All's well but now i have a symbol on the stage called mc-home.  inside of mc-home is a button called btn-go.
    On the stage in composition ready there's a variable sym.setVariable("current", "mc-home");
    This code works for a symbol that's on the stage but, how do i get this code to work on a button that's inside another symbol that's on the stage?
    var current = sym.getVariable("current");
    if (current != "") {
        sym.getSymbol(current).play("OUT");
    sym.getSymbol("mc-something").play("IN");
    sym.setVariable("current", "mc-something");

    sorry, i was kind of confused myself too, don't worry about it but thanks for your patience for reading it anyway

  • How to access a variable from one mxml to another mxml?

    I have Vbox having Hbox in turn hbox has some components ...TextInput...
    I m adding this Vbox in another mxml file....iteratively ....
    I need the sum of all the enetered values in the text boxes to be displayed on the textbox in another Mxml ...
    I am taking sum in a variable and want to show tha some in another file...
    How can I get that variable in my resultant mxml??
    TIA

    In this case it is best to use custom events to pass data. Here are some resources:
    http://chikaradev.com/learning/flex3/customevents/StudentsTutoringCustomEvents1.pdf
    http://chikaradev.com/learning/flex3/customevents/CustomEvents3/CustomEvents3.html
    http://livedocs.adobe.com/flex/3/html/help.html?content=createevents_3.html
    If this post answers your question or helps, please mark it as such.
    Greg Lafrance - Flex 2 and 3 ACE certified
    www.ChikaraDev.com
    Flex / AIR Development, Training, and Support Services

  • How to access getter/setters from the entity classes

    Let me brake my question to two:
    1. in My JSP page, I need to get an exception from either the entity or the view class if I insert a duplicate value into the associated table. How can I do that?
    2. How can I access the entity's getter/setter functions in the JSP page?
    Thank you

    Let me brake my question to two:
    1. in My JSP page, I need to get an exception from either the entity or the view class if I insert a duplicate value into the associated table. How can I do that?You can mark the attribute as unique key attribute and choose to implement the unique-key validation in the Bc4J side. See help on UniqueKey and how to establish such validation
    2. How can I access the entity's getter/setter functions in the JSP page?You cannot access entities directly. You have to expose the accessors via ViewObject Rows and use those Rows from the JSP/or any client side.
    Thank you

  • Accessing a variable form a super class

    Hi guys, its my first post in this forum, i am student and learning some java. I find it very interesting but have some problems
    My question is : How to access a variable from a superclass
    Here is my program:
    class superclass
         int i = 10, j= 20;
         void display()
         System.out.println("i in super is:" +i);
         System.out.println("j in super is:" +j);
    class child extends superclass
         int i,j;
         void display()
         System.out.println("i in child is:" +i);
         System.out.println("j in child is:" +j);
    class prgdemo
         public static void main(String args[])
         superclass s =new superclass();
         s.display();
         child c = new child();
         c.display();
    }Thanks for your replies

    This is only true of nested subclasses. Private
    fields are HIDDEN to ALL code contained outside of
    the enclosing class.You are a very bad racist man:class superclass {
         private int i = 10;
         private int j= 20;
         public class child extends superclass
              int i= 42,j= 54;
              void display()
              System.out.println("i in child is:" +i);
              System.out.println("j in child is:" +j);
              System.out.println("super's i is:" +super.i);
              System.out.println("super's j is:" + super.j);
              System.out.println("outer's i is:" + superclass.this.i);
              System.out.println("outer's j is:" + superclass.this.j);
         void display()
         System.out.println("i in super is:" +i);
         System.out.println("j in super is:" +j);
    }kind regards,
    Jos (eeeww!)

  • How to read static variable defined java class from flex?

    This is a beginner question. If I use remoteClass to map a java class and a flex class, how can I access a static variable defined in java class from the flex code?
    Thanks!

    Static propeties are by default ignored in the blazeds for serialization. You can try using another global property in the java bean which maps to the value stored in the static property( Hopefully it should work)
    eg,
    public String instanceValue = ClassName.staticValue;
    Ref: http://livedocs.adobe.com/blazeds/1/blazeds_devguide/help.html?content=serialize_data_3.ht ml

Maybe you are looking for

  • [SOLVED] - Printing to a Windows XP printer

    I've already installed cups, samba, gutenprint, foomatic and hplip packages. I need to print from my arch laptop to a printer linked to a Windows XP desktop pc. The printer and the desktop are elsewhere, so I had to link my two pc with a vpn using Ha

  • Left speaker output failed, gigaworks s750

    I have seen this problem on the forum before, here is one instance: http://forums.creative.com/creativel....id=70289#M493 I havent seen any solutions. Setup: Asus n78x-e deluxe motherboard with 5.1 capability Usually i have it plugged: rear-> line in

  • Delete request / role in ERM GRC 5.3

    Hi All I have a Role in ERM that I need to delete. Buuut, Role deletion is not possible; it has sent for approval. In CUP we have already deleted all request (following instructions by SAP note) and there is not any request in the system. The problem

  • RT not updating my NI9474

    I have Labview 8.5, cRIO 9014 and 2 NI 9474 DO modules. In my FPGA VI, I have 5 loops.  The first loop deals with my 9474 cars.  I have boolean values as inputs to that when the boolean is one, the DO# will turn on.  This loop runs 1 time.  In side F

  • Using procmail as MDA

    I am trying to move from 10.3 Client to Snow Leopard Server on a Mac Mini. My problem is configuring my mail system. In my previous setup, mail was delivered to postfix. The mailbox_command configuration line caused it to be sent to procmail for loca