Accessing static variable using GWT remote servlet

Hi all,
Using GWT, I'm trying to call two methods which exist in a
RemoteService from my entrypoint class.
I have two methods within my remoteService servlet, method A and
method B.
Method A returns an int and sets an arraylist.
Method B returns the arraylist, myList.
I'm assuming that a single callback is associated with a single
servlet method? Is it possible to access the arraylist, which has been
set from calling method A, using the callback?
e.g.
//client code:
               MyServiceAsync myService = (MyServiceAsync)
GWT.create(MyService.class);
               AsyncCallback callback = new AsyncCallback(){
                  public void onSuccess(Object result) {
                  public void onFailure(Throwable caught) {
              myService.foo(callback);
// servlet code
public class MyServiceImpl extends RemoteServiceServlet implements
MyService{
       public static List myList = new ArrayList();
       public int A(){
               setB();
               return 10;
       public void setB(){
               // this adds five elements to a static arraylist, myList
       public List getB(){
               return myList;
}

Ok, frist solution (the better one) is that You can create a class that will both contain the int and the list. E.g.
public class MyObject implements Serializable {
private int value;
private List<Object> list;
//getters and settersThen You can set the values You're interested in the RemotServiceServlet and simply return this object - aync callbacks can return various types of objects (not only primitives) but under two conditions:
1) The object must implement the Serializable interface
2) The object must have public no argument constructor or no constructor at all.
Then in your client class You'll have:
MyServiceAsync myService = (MyServiceAsync) GWT.create(MyService.class);
AsyncCallback<MyObject> callback = new AsyncCallback<MyObject>(){
public void onSuccess(MyObject result) {
  result.getList();
  result.getInt();
public void onFailure(Throwable caught) {
myService.A(callback);
};The second solution is to invoke a method B callback in the result of A's callback:
MyServiceAsync myService = (MyServiceAsync) GWT.create(MyService.class);
AsyncCallback aCallback = new AsyncCallback(){
public void onSuccess(Object result) {
   //here You get the in value
   AsyncCallback bCallback = new AsyncCallback(){
    public void onSuccess(Object result) {
     //here You get the list
    public void onFailure(Throwable caught) {
    myService.B(bCallback);
public void onFailure(Throwable caught) {
myService.A(aCallback);Hope this is clear and will help You. (Remember also the use generics!)

Similar Messages

  • Accessing ICS variable using EL

    Can we access ics variable using EL. Hope this query is already posted. but I tried the solution. it is not working
    I have set an  ics variable in a CSElement and I tried to access that in the next line using EL. but I am not getting the values
    e.g
    <%
    ics.SetVar("testvar","testvalue")
    %>
    fetching value using cs : {cs.testvar}
    fetching value using ics : {ics.testvar}
    No results for both the line. Is it not possible to access ics object using EL?

    Hello
    Could you try something like:
    e.g
    <%
    ics.SetVar("testvar","testvalue")
    %>
    fetching value using cs : ${cs.testvar}
    Hope it helps.
    Gerardo

  • How to access Websphere variables using java

    Hi
    I want to access Websphere variables using java.
    Any help is appreciated!!
    Thanks
    P

    WebSphere Application Server has a bunch environmental variables such as log locations. These are held at the "server", "node", and "cell" level.
    To access them, you have to get the right context. Something like this, I believe...
    InitialContext initialContext = new InitialContext();
    initialContext.lookup("foo:bar/baz/blah"); //correct context hereGo to the IBM website for WAS and do a search on namespace bindings. That should give you some more information.
    Good luck.

  • Accessing database Variables using JDBC

    Hi,
    I have a question for some of you Java specialists out there.
    I want to execute a select statment in my database (SQL Server 2000) and store the output in a variable. - The reason I am not directly executing the SQL statement from my JDBC connection is that I need to execute a number of SQL statements and then finally would like to store my result set in a variable in the database - NOW, my question is , how do I (If I can) access a database variable using either servlets or JSP. Any help is welcome.
    A quick response would be much appreciated.
    thanks

    We are probably talking about different things.
    ASP, at least when I used consisted of the following:
    -html
    -server side script (vbscript, javascript, perlscript)
    -client side script (usually javascript but it could be vbscript and perlscript)
    In the above you have three possible kinds of variables java, perl, vb. In each of those languages you can use SQL text to manipalate data in the database. However the text itself never ran in the ASP server nor was there such a thing a SQLscript, so there was nothing that was a SQL variable.
    However, if I write a stored procedure in Oracle, it can definitely have variables. And likewise a oracle package can have variables. But there is no way to directly use those variables in ASP. The value of the variable would have to be returned to the ASP script language and a variable in tha language could contain that value.
    Perhaps I just don't understand ASP or it has evolved in the last 3 years. If so then ignore everthing I have said.

  • Accessing Private variable using reflection

    Is someone have code snippet for accessing private varaible using reflection
    Here is my code snipper
    import java.lang.reflect.Field;
    public class test1234 {
    private String t;
    public test1234() {
    public String show() {
    return t;
    import java.lang.reflect.Field;
    public class Test123 {
    public Test123() {
    public static void main(String[] args) {
    test1234 test12341 = new test1234();
    try {
    Class cls = test12341.getClass();
    Field fld = cls.getField("t");
    fld.set(test12341, "12");
    catch (Exception e) {
    System.out.println(e.getLocalizedMessage());
    I am getting exception when i try to access.
    java.lang.NoSuchFieldException
         at java.lang.Class.getField0(Native Method)
         at java.lang.Class.getField(Class.java:826)
         at Test123.main(Test123.java:24)
    Thanks in advance

    Thanks for your response. After setting accessible to true i can able to set into private variable.
    Thanks a lot.

  • Why Inner class cannot access static variables

    Why is it that inner class can use only static final variables of the outerclass, and not ordinary static variables of the outer class. "Yes the JLS sepcifies that only final static variables can be used inside an inner class, esp a non blank final variable". But why this restriction.
    Thanks.

    so what are final static variables treated as if they
    are not variables. So if the final static value is
    not loaded when the class is loaded how will the
    class know about the value.??The actual value wil be substituted for the name of a static final value at compile time. That's why you can use them in switch statements where you can't use any variable variable.
    This is something to watch out for, by the way, because if you use a public static final value from one class in another the actual value will be compiled into the using class, so if you change the value where it's defined the class using it will have the old value until it's recompiled.

  • Static Variable using Dynamic Variable

    I have a need to display different variations of the current date across multiple reports - for example: YYYYMM, MMYYYY, YYYYDD, etc.
    I thought I could create an initialization block that maps three variables containing - YYYY, MM and DD.
    In the Static Variable I was going to do the different concatenation of these variables. I see in the Static Variable it allows me to go in and select repository variables in the Expression Builder, so if had two Dyanmic Variables (VarYYYY and VarMM) I select these for my new Static Variable and concatenate them (Valueof(VarYYYY) || Valueof(VarMM).
    However, when I go to the report and display this variable it displays just the text above, treating it like a string value, so all I see in the report is:
    Valueof("VarYYYY") || Valueof("VarMM")
    I am referencing in the report with the syntax
    @{biServer.variables['StaticVarName']}
    Is there a reason why it does not display the variable values?
    Thanks

    mmm some solution could be to write the same insert with decode/case statement and put there the conditions that you want.
    maybe something like this:
    SQL> ed
    Wrote file afiedt.buf
      1  begin
      2    for i in 1..10 loop
      3      insert into t1 (col1,col2,col3)
      4        values (i,
      5                decode (mod (i,2),0,i,null),
      6                decode (mod (i,3),0,i,null));
      7    end loop;
      8* end;
    SQL> /
    PL/SQL procedure successfully completed.
    SQL> select * from t1;
          COL1       COL2       COL3
             1
             2          2
             3                     3
             4          4
             5
             6          6          6
             7
             8          8
             9                     9
            10         10
    10 rows selected.
    SQL> truncate table t1;
    Table truncated.
    SQL> insert into t1 (col1,col2,col3)
      2    select rownum,
      3           decode (mod (rownum,2),0,rownum,null),
      4           decode (mod (rownum,3),0,rownum,null)
      5    from dual
      6  connect by rownum <=10;
    10 rows created.
    SQL> select * from t1;
          COL1       COL2       COL3
             1
             2          2
             3                     3
             4          4
             5
             6          6          6
             7
             8          8
             9                     9
            10         10
    10 rows selected.forgot that you are not using anymore the loop :)
    Message was edited by:
    Delfino Nunez

  • Slow performance when multiple threads access static variable

    Originally, I was trying to keep track of the number of function calls for a specific function that was called across many threads. I initially implemented this by incrementing a static variable, and noticed some pretty horrible performance. Does anyone have an ideas?
    (I know this code is "incorrect" since increments are not atomic, even with a volatile keyword)
    Essentially, I'm running two threads that try to increment a variable a billion times each. The first time through, they increment a shared static variable. As expected, the result is wrong 1339999601 instead of 2 billion, but the funny thing is it takes about 14 seconds. Now, the second time through, they increment a local variable and add it to the static variable at the end. This runs correctly (assuming the final increment doesn't interleave which is highly unprobable) and runs in about a second.
    Why the performance hit? I'm not even using volatile (just for refernce if I make the variable volatile runtime hits about 30 seconds)
    Again I realize this code is incorrect, this is purely an interesting side-expirement.
    package gui;
    public class SlowExample implements Runnable
         public static void main(String[] args)
              SlowExample se1 = new SlowExample(1, true);
              SlowExample se2 = new SlowExample(2, true);
              Thread t1 = new Thread(se1);
              Thread t2 = new Thread(se2);
              try
                   long time = System.nanoTime();
                   t1.start();
                   t2.start();
                   t1.join();
                   t2.join();
                   time = System.nanoTime() - time;
                   System.out.println(count + " - " + time/1000000000.0);
                   Thread.sleep(100);
              catch (InterruptedException e)
                   e.printStackTrace();
              count = 0;
              se1 = new SlowExample(1, false);
              se2 = new SlowExample(2, false);
              t1 = new Thread(se1);
              t2 = new Thread(se2);
              try
                   long time = System.nanoTime();
                   t1.start();
                   t2.start();
                   t1.join();
                   t2.join();
                   time = System.nanoTime() - time;
                   System.out.println(count + " - " + time/1000000000.0);
              catch (InterruptedException e)
                   e.printStackTrace();
               * Results:
               * 1339999601 - 14.25520115
               * 2000000000 - 1.102497384
         private static int count = 0;
         public int ID;
         boolean loopType;
         public SlowExample(int ID, boolean loopType)
              this.ID = ID;
              this.loopType = loopType;
         public void run()
              if (loopType)
                   //billion times
                   for (int a=0;a<1000000000;a++)
                        count++;
              else
                   int count1 = 0;
                   //billion times
                   for (int a=0;a<1000000000;a++)
                        count1++;
                   count += count1;
    }

    Peter__Lawrey wrote:
    Your computer has different types of memory
    - registers
    - level 1 cache
    - level 2 cache
    - main memory.
    - non CPU local main memory (if you have multiple CPUs with their own memory banks)
    These memory types have different speeds. Depending on how you use a variable affects which memory it is placed in.Plus you have the hotspot compiler kicking in sometime during the run. In other words for some time the VM is interpreting the code and then all of a sudden its compiled and executing the code compiled. Reliable micro benchmarking in java is not easy. See [Robust Java benchmarking, Part 1: Issues|http://www.ibm.com/developerworks/java/library/j-benchmark1.html]

  • Accessing static variables

    class Array{
    static int m = 10; // how to access this variable in main()?
    public static void main(String [] args) {
    int m = 45;
    System.out.print(m );
    return ;
    }

    One problem is you are doing stuff in main that should not be done in main.
    Main is always only for kicking a program off and ensuring it cleans up nice when done, that is it. Sooner you figure this out and get into good habits the better.
    Second, you have two m variables, which one do expect to get accessed? But still, getting out of main before doing your computations will make your problem much easier to see and fix, so do that first.
    JSG

  • Accessing TestStand Variables using Applicatio​n Manager

    I am working with an Operator Interface written in LabWindows/CVI 7.1.  I need this program to be able to access station globals and local variables in TestStand 3.1.  This Operator Interface was originally written for TestStand 2 and uses the older functions like TS_NewEngine, TS_EngineSetProperty, TS_PropertyGetValString, etc.  This has caused some problems when I try to use these functions with TestStand 3.1.  I can run the code fine in the debugger, but my executable just quits as soon as it encounters one of these older testStand functions (I can't tell which one).  I have been trying to incorportate the Application Manager, Sequence File View Manager, and Execution View Manager into the existing code without altering the GUI's appearence (keeping with the standard LabWindows text boxes and not using ActiveX controls).  I cannot figure out how to access variables in testStand using the Managers.  Here is the code I am using so far:
    //Define Panel Handles and ActiveX Control Handles
    typedef struct
     //panel handles
     int              m_pnMain;
     int              m_pnExecute;
     // ActiveX control handles:
     CAObjHandle applicationMgr;     // invisible control, manages Startup/Shutdown, and other application functions
     CAObjHandle sequenceFileViewMgr;   // invisible control, manages a SequenceView control that displays loaded sequence files
     CAObjHandle executionViewMgr;    // invisible control, manages a SequenceView control that displays executing sequences
     CAObjHandle m_oEngine;
     } ApplicationWindow;
    static ApplicationWindow gMainWindow; // this application only has one window
       // load the panels for the main window from the .UIR file
       errChk( gMainWindow.m_pnMain = LoadPanelEx (0, "Symtx Operator Console.uir", PN_MAIN, __CVIUserHInst));
       errChk( gMainWindow.m_pnExecute = LoadPanelEx (gMainWindow.m_pnMain, "Symtx Operator Console.uir", PN_EXECUTE, __CVIUserHInst));
       // prepare to use the TestStand ActiveX controls
       errChk( GetActiveXControlHandles());
       tsErrChk( TSUI_ApplicationMgrGetApplicationWillExitOnStart(g​MainWindow.applicationMgr, &errorInfo, &appWillExitOnStart));
       if (!appWillExitOnStart)
        // show a splash screen while starting up
        errChk( splashPanel = LoadPanelEx(0, "Symtx Operator Console.uir", SPLASH, __CVIUserHInst));
           errChk( InstallPopup(splashPanel));
       // make TS engine conveniently accessible
       tsErrChk( TSUI_ApplicationMgrGetEngine(gMainWindow.applicati​onMgr, &errorInfo, &gMainWindow.m_oEngine)); 
    The code shown above works fine.  I tried to add the following lines to access the station globals:
       // Get station globals
       m_oGlobals = gMainWindow.m_oEngine.NewPropertyObject( 3, False, "", 0); 
       m_oGlobals = gMainWindow.m_oEngine.Globals;
    and got the following error when I compiled:
      290, 39   Left operand of . has incompatible type 'CAObjHandle'.
    which referred to
    m_oGlobals = gMainWindow.m_oEngine.NewPropertyObject( 3, False, "", 0); 
    If anyone can help I'd greatly appreciate it.

    Hi there,
    The reason the code for TestStand globals does not work is because CVI does not support using the TestStand API in this way.  This can be a little confusing because in the help it lists using these methods and functions to access the properties you were looking for, however, in CVI you still have to use the TS_ functions to access different properties.  Usually it is TS_objectToOperateOn.  For example TS_Engine will always be getting properties or executing methods of the engine.  I have put some code below that should accomplish the same thing you were looking to do.  Hope this helps out!
        int error = 0;
        ErrMsg errMsg = {'\0'};
        ERRORINFO errorInfo;
        CAObjHandle myGlobals;
        //Get the globals from the engine
        tsErrChk (TS_EngineGetGlobals (myEngine, &errorInfo, &myGlobals)); 
        //Store the last user name into a local string
        tsErrChk (TS_PropertyGetValString(myGlobals, &errorInfo, "TS.LastUserName", 0, &lastUserName));
    Error: 
        // FREE RESOURCES
        if (lastUserName != NULL)
             CA_FreeMemory(lastUserName);
        // If an error occurred, set the error flag to cause a run-time error in TestStand.
        if (error < 0)
             *errorOccurred = TRUE;
            // OPTIONALLY SET THE ERROR CODE AND STRING
             *errorCode = error;
             strcpy(errorMsg, errMsg);
    Pat P.
    Software Engineer
    National Instruments

  • 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 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 ) ;

  • Accessing session variables

    Hi ,
    I have session variable defined using portals (forms or plsql portlets).
    Can i access these variables using jsp portlets ??
    This is an urgent requirement ..
    Regards,
    Vijaya

    "145822",
    If your application with application id 100, for example, uses a common authentication scheme with application 200 (using the same cookie name in the case of an HTML DB style authentication scheme), then the two applications can run in the same session. A potential benefit of this, even if the two apps are not intricately related, is that the user has only to authenticate once per new session and will have access to both apps. If you set it up this way, then app 100 can access app 200's items in the same session using this function from within app 100:  htmldb.application.fetch_app_item(p_item=>'ITEM_NAME',p_app=>200);Scott

  • Static variable/method

    Hi!!
    need help here..how can i access static variable and methods
    in a class?
    tnx.

    tnx for the reply..I want to access the treeData under the
    hierarchicalCollectionView property of advanceDatagrid.
    what i did is
    private var myGrid:AdvancedDataGrid = new AdvancedDataGrid();
    myGrid.hierarchicalCollectionView.treeData;
    and i got this error
    1119: Access of possibly undefined property treeData through
    a reference with static type
    mx.collections:IHierarchicalCollectionView. advancedgrid/src
    well!! im sure treeData is existing i run debug and its
    there. So it came up that it might be a static variable of method.
    I tried to do some experiments and i found out static methods and
    variables are not accessible outside the class.
    tnx.

  • 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.

Maybe you are looking for

  • HP Omni 27-1054 As A Monitor

    I am attempting to use my Omni 27 as a monitor for a new desktop tower I have purchased, and it does not seem to be registering the input from the HDMI port. The buttons aren't working to switch between the normal input and the HDMI input, and I can'

  • Programming PLDs with LabView 5.01

    Hello I have to programm an ALTERA PLD. I have the Input File *.JBC (binary) or *.JAM (ASCII). There is an interpreter called JAM-Player (http://www.jamisp.com) available. How can I include these programming sequence in LabView? Has anyone already do

  • Handoff isn't working at all on my Macbook Pro or iPhone 6. I need help please.

    I updated all my stuff but Handoff and Continuity are not working at all. I have been through it all with setting everything up how it says. YES BLUETOOTH IS ON!

  • GuiXT on FBL5N

    Hi, I'm new to GuiXT, and I've read about the documentation on GuiXT.  Normally it's used to customizing the selection options on a standard SAP transaction.  I have a requrirement to add extra fields on the output of FBL5N and append an already deve

  • Canon Auto Focus

    Hi All, I was using my Canon 24-70 with the Metabones MK IV adapter. When I put the lense into auto focus and then use the push to auto focus button, the lense would rack focus back and forth but never grab it. Just curious if 1) Is this something th