Calling a method after 10 seconds

Hello,
I need to call a method after 10 seconds. That is to make sure that if one particular field is updated, say 3 times in a window of 10 seconds, I should just be able to take the last value and process it, in my ajax app. I am so far using the Timer class, but the problem is, it ticks off a thread for every single request to be processed after 10 seconds and processes all the 3 requests, where as I should just be running that method once for the last request. Could you please help me with this ?
Cant do this at the client level, for the page may be closed within those 10 seconds of the event and the setTimeout wont work then.
This is what I made so far.:
final Map<String, Object> mp = new HashMap<String, Object>();
if(form.getEmpId() != null )
            mp.put(form.getEmpId().toString(), form);
            new java.util.Timer().schedule(new java.util.TimerTask()
               public void run()
                  EmpForm form1 = (EmpForm)mp.get(empId.toString());
                  String empId = form1.getempId().toString();
                  String value1Changed = form1.getValue1Changed().toString();
                  String value2Changed = form1.getValue2Changed().toString();
                  myService.changeData(empId, value1Changed, value2Changed),
            }, 10000);
         }

Thanks for replying
tjacobs01 wrote:
My recommendation is that you share an AtomicReference between your timer and the listener that is receiving the updates. This way, the listener can just update the value, and the timer uses the latest one when it wakes upOk, out of my limited understanding, I looked up AtmoicReference and found it a class. I think I cant use that since I am maintaining a list of empIds against the object that holds their data in a hashmap, expecting the map to override the empId on the second request. So, I made a final map and thought Id just push the timer scheduler method in another method, but the problem is, for me to ask that thread (which I expect to run after 10 seconds of my calling) to run, I need to call it somewhere, and as soon as I get a request I am calling the method which runs/ticks off the thread.
I was thinking that since I am passing and using a final map (that I declared as a class level variable), I will be able to put update the map object and whenever the thread runs, will fetch the latest value (of the empId) in the map. But I guess I am doing it wrong. :(

Similar Messages

  • How to call a method after a page  complete load

    Hi,
    Environment: JSF1.2.12+Spring
    I have a startpage, i will call a methode after startpage complete load. (I do not want to use javascript)
    How can i implement it.
    Edited by: zlzc2000 on Nov 6, 2009 2:53 AM

    goal: optimize load startpage(accelerate to load startpage)
    in startpage i use sql to load user's information, that in startpage is required.
    in other page i need the complete User Object (hibernate load user Object).
    i want to after dispay startpage load the user Object whith Hibernet.
    if during load startpage with hibernate to load user object, that is too slow.
    concept: 1step: with sql load user information (not full, for example: id, forename, surname,...)
    2step: results display( load startpage )
    3step: after load complete startpage, call method to load user object(it include all information of user )
    then the user object can be uesed in anywhere in the future.
    but i dont know how to impement it.
    Edited by: zlzc2000 on Nov 6, 2009 3:37 AM

  • Any way (event) to call Java method after view created in JSF 2.0

    Hi,
    I am using JSF 2.0 Mojarra's implementation.
    I am interested to know if there is a way to call Java methods before and/or after view has been restored.
    I wanted to initialize data for my page in this Java method.
    I could see there is an event class PostRestoreStateEvent added in JSF 2.0. How to use it?
    I tired to use f:event element as below, but it does not work. Can anyone share anyother idea to achieve this behaviour?
    <f:metadata>
    <f:event type="postRestoreState" listener="#{employeeLoadBean.loadAfterRestoreView}"/>
    </f:metadata>
    Regards,
    Kishore K S

    Hi,
    The problem is solved as below.
    <f:metadata>
    <f:event type="javax.faces.event.PostRestoreStateEvent" listener="#{employeeViewEventListener.postRestoreState}"/>
    </f:metadata>
    The above calls the Java method #{employeeViewEventListener.postRestoreState} whenever View has been restored.
    It was not working when shortName of the event (ie., postRestoreState) is given and throwing ClassNotFound exception.
    Regards,
    Kishore K S

  • Unable to call bean method at second JSP.

    I have a Bean called "Database" in that two methods
    1.public String methodReturnsString()
    2.public List methodReturnsList()
    And also i have three jsp's.
    1.First.jsp
    2.Success.jsp
    3.fail.jsp
    i called methodReturnsString of "Database" in the First.jsp ,after receiving intended String from the method methodReturnsString() i.e "success" or "fail" i can goto Success.jsp. or fail.jsp.
    Assume i got String "success" eventually leads me to Success.jsp , In this Success.jsp i was trying to access Bean method methodReturnsList() , Now the problem is I cant access the Bean method methodReturnsList() in Success.jsp, where i want to print the List that is returned by methodReturnsList().
    Can anybody tell me what is the mistake i am doing.
    here is "Success.jsp"
    <%@ page contentType="text/html"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
    Login Successful
    <html>
    <f:view>
       <h:form id="result">
         <p>
                 <c:forEach var="x" items="${Database.methodWithList}" >
              ${x}
         </c:forEach>
                </p>
           </h:form>
    </f:view>
    </html>here is" Faces-config.xml"
    <?xml version="1.0"?>
    <!DOCTYPE faces-config PUBLIC
      "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
      "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
    <faces-config>
         <managed-bean>
              <managed-bean-name>Database</managed-bean-name>
              <managed-bean-class>com.persistent.parashar.database.Database</managed-bean-class>
              <managed-bean-scope>session</managed-bean-scope>
         </managed-bean>
         <navigation-rule>
              <from-view-id>/First.jsp</from-view-id>
              <navigation-case>
                   <from-action>#{Database.methodReturnsString}</from-action>
                   <from-outcome>success</from-outcome>
                   <to-view-id>/success.jsp</to-view-id>
              </navigation-case>
              <navigation-case>
                   <from-action>#{Database.methodReturnsString}</from-action>
                   <from-outcome>fail</from-outcome>
                   <to-view-id>/fail.jsp</to-view-id>
              </navigation-case>
         </navigation-rule>
    </faces-config>
    Here is Database.java
    public class Database {
         public List methodWithList()
              System.out.println("Contents in the List#########");
              List al=new ArrayList();
              al.add("jaya");
              al.add("chandra");
              al.add("raheem");
              al.add("balu");
              System.out.println("Contents in the List"+al);
              return al;
         public String methodReturnsString()
              return "success";
    }

    Thank you for reply, after making few chages by taking your suggestion i am still struggling to get the desired result in my jsp. please into the code below
    public class Database {
            public List calToDatabase;
         public static void initialCalToList()
              System.out.println("Contents in the List#########");
              List al=new ArrayList();
              al.add("JAya");
              al.add("chandra");
              al.add("raheem");
              al.add("balu");
              System.out.println("Contents in the List"+al);
              Database db= new Database();
              db.setCalToDatabase(al);  // calling the setter with list as an argument
    public List getCalToDatabase() {
              return calToDatabase;
         public void setCalToDatabase(List calToDatabase) {
              this.calToDatabase = calToDatabase;
         }I have also made changes in success.jsp
    <%@ page contentType="text/html"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
    Login Successful
    <html>
    <f:view>
       <h:form id="result">
         <p>
               <c:forEach var="x" items="#{Database.getCalToDatabase}" >
                     ${x}
                   </c:forEach>
         </p>
       </h:form>
    </f:view>
    </html>

  • How to call a method of an other view in the current view

    Hi Guys,
    I have 2 views in my Project: IPrivateValidateIncidentView and IPrivateRoadMapView.  Now, a button in the IPrivateRoadMapView must call a method in the IPrivateValidateIncidentView.  I cannot seem to figgure this out.  I know that I will probably need to arrange things centrally in my Component COntroller somehow.
    I have tried to see what methods I can Invoke on IPrivateValidateIncidentView from within the Controller to see if I can call the method OnActionDoneValidate() from there, but I can only seem to get a constant with this methods name: IPrivateValidateIncidentView.WD_EVENTHANDLER_ON_ACTION_DONE_VALIDATION;
    Please help.
    Christiaan

    Hi,
    You are correct, for your requirement you need to arrange the things centrally that is in Component Controller. As in above reply you need to Create your context in Component controller and then map them to both the views. So data will be available to both the views and finally you create a method in component controller and call that method from second view. So the data changes made in controller will be reflected on First View as they have context mapping.
    Regards
    Raghu

  • JNI - core dump - internal error on linux after calling Java method

    I'm getting a core dump after calling athe main statric method using JNNI.
    On linux.
    I can get the class id correcttly but when I attempt to call the method it craches with an internal error , anyone know why it would crash instead of just not work.
    if(cls)
        main_methodID = env->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");
           printf("Class Found Successfully\n");
      else
        printf ( "cls not found\n");
        return 0;
      if(main_methodID)
              jstring first_str = env->NewStringUTF("The First String");//create string
              jobjectArray args = (jobjectArray)env->NewObjectArray(1,env->FindClass("java/lang/String"), first_str);//new array with 2 elements
                   env->SetObjectArrayElement(args, 2, first_str);//insert the second string into index 1 of the array
              jstring second_str = env->NewStringUTF("The Second String");//create string
              env->SetObjectArrayElement(args, 1, second_str);//insert the second string into index 1 of the array
         env->CallStaticVoidMethod(cls, main_methodID, args);//pass the array to the Java main method
                                  The JAVA method is
      public static void main(String[] args) {
        System.out.println("Main method in Framework");
            Framework framework = new Framework();
                                 

    I see yere points but what I see on linux is it makes it to the constructor of the Java object and somewhere afterwards it bails out, the Java app does work alone. It appears to have problems initializing the JFrame, could there be a problem with the Java inheritance when a JVM is invoked throurgh native invocation??
    Here's some of the Java stuff
    public class Framework extends WindowAdapter {
        public int numWindows = 0;
        private Point lastLocation = null;
        private int maxX = 500;
        private int maxY = 500;
        public Framework() {
            System.out.println("JAVA Framework cnst");//GETTING HERE
            makeNewWindow();
        public void makeNewWindow() {
            System.out.println("JAVA makeWindow"); //GETTING HERE
            JFrame frame = new MyFrame(this); //NOT GETTING HERE!!!!!!!!!
            numWindows++;
            System.out.println("Number of windows: " + numWindows);
            System.out.println("Frame location: " + lastLocation);
            frame.setVisible(true);
            System.out.println("Post Java set frame visible");
        public static void main(String[] args) {
        System.out.println("Main method in Framework");
            Framework framework = new Framework();//GETTING HERE
    class MyFrame extends JFrame {
        protected Dimension defaultSize = new Dimension(200, 200);
        protected Framework framework = null;
        public MyFrame(Framework controller) {
            super("New Frame");
            System.out.println("MyFrame cnst ");//NOT GETTING HERE!!!!!!
            framework = controller;
            setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            addWindowListener(framework);
            JMenu menu = new JMenu("Window");
            menu.setMnemonic(KeyEvent.VK_W);
           setSize(defaultSize);
    }

  • How to call a javascript method after table load on JSFF Fragment load?

    Hello,
    The usecase is to invoke a javascript method after table is done loading (fetching data) when user lands to a JSFF fragment. With JSPX pages I can achieve that by using PagePhaseListener. I have tried with RegionController as follows, and the problem i face is that I cannot prevent multiple calls to the Javascript call when user presses a tab or button in a screen, or changes drop-down value with autosubmit on.
    import javax.faces.context.FacesContext;
    import oracle.adf.model.RegionBinding;
    import oracle.adf.model.RegionContext;
    import oracle.adf.model.RegionController;
    import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
    import org.apache.myfaces.trinidad.util.Service;
    public class MyListener implements RegionController{
    public MyListener() {
    super();
    @Override
    public boolean refreshRegion(RegionContext regionContext) {
    int refreshFlag = regionContext.getRefreshFlag();
    System.out.println("Render flag is: "+refreshFlag);
    if (refreshFlag == RegionBinding.PREPARE_MODEL)
    initializeMethod();
    regionContext.getRegionBinding().refresh(refreshFlag);
    return false;
    public boolean validateRegion(RegionContext regionContext) {
    regionContext.getRegionBinding().validate();
    return false;
    public boolean isRegionViewable(RegionContext regionContext) {
    return regionContext.getRegionBinding().isViewable();
    public void initializeMethod() {
    FacesContext f = FacesContext.getCurrentInstance();
    ExtendedRenderKitService service = Service.getRenderKitService(f, ExtendedRenderKitService.class);
    service.addScript(f, "myJSFunction();");
    @Override
    public String getName() {
    return null;
    I need the javascript to be called only once after the table is done loading when user lands to a fragment (jsff).
    Any ideas appreciated?
    JDeveloper version is 11.1.1.5.0
    Thank you.
    Valon
    Edited by: Valon on Apr 11, 2013 3:10 PM

    One of the requirements is to compare every row with the next row and highlight the changes. There are other requirements as well where JavaScript solution is used.
    The question remains the same. Is it doable or not without changing the solution from JavaScript solution to server-side solution ? Can we call a JavaScript only once when the user lands to a jsff fragment ?
    Hope that is clear.
    Thanks.
    Valon

  • How to call  a javascript method after the PPR event has finished  ?

    Hi!
    How can we make a javascript method get called after the processing of ADF PPR event?
    My specific use case is,
    I want to call a javascript function after the data in the table is loaded...
    In 10g, that is not a problem, as the data used to get loaded directly during onLoad, and so i would call my js function on load;
    but in 11g , the table data is being loaded through PPR which is initiated onload, and so i needed to call my function after the PPR Response processing has been done; for which I need the name of the event triggered at that instance.
    Is it possible to do this?
    Regards,
    Samba

    Hey, I got it.
    I handled the ADF Controller's PREPARE_RENDER_ID phase of the lifecycle, and then called the
    script to get Executed.
    The code :
        public void afterPhase(PagePhaseEvent pagePhaseEvent) {
            FacesPageLifecycleContext ctx = (FacesPageLifecycleContext)pagePhaseEvent.getLifecycleContext();
                 if (pagePhaseEvent.getPhaseId() == Lifecycle.PREPARE_RENDER_ID) {
                    if(AdfFacesContext.getCurrentInstance().isPostback() )
                        afterRender();
        }is written in lifecycle listener , and my backing bean extended this listener ,
    and in the afterRender() method I did this :
       public void  afterRender(){
                System.out.println("AFTER RENDER CALLED");
               FacesContext context = FacesContext.getCurrentInstance();
               ExtendedRenderKitService service = (ExtendedRenderKitService)Service.getRenderKitService(context, ExtendedRenderKitService.class);
               service.addScript(context, "translate();");
           }That's it.
    It did work, magnificently.
    Thanks for the idea.
    Regards,
    Samba

  • Calling a backing bean method after load of fragment in adf

    I needed to call a backing bean method after page load of fragment in adf.
    I used the method suggested in:
    https://community.oracle.com/message/11044570
    only difference is im giving the if clause as:
    if (refreshFlag == RegionBinding.RENDER_MODEL ) {
    instead of
    if (refreshFlag == RegionBinding.PREPARE_MODEL)
    It was working fine, but page was not getting refreshed so used the code as mentioned in example:
    public void refresh() {
              FacesContext facesContext = FacesContext.getCurrentInstance();
              String refreshpage = facesContext.getViewRoot().getViewId();
              ViewHandler  viewHandler =facesContext.getApplication().getViewHandler();
              UIViewRoot viewroot =  viewHandler.createView( facesContext, refreshpage);
              viewroot.setViewId(refreshpage);
              facesContext.setViewRoot(viewroot);
    Now issue is once page is loaded and backing bean method is called, the refresh code refreshes the page and upon page load, refresh method is called again in recursive fashion.
    please advise what to do in such scenario?
    I tried to do selective refresh using some variable(also with static) but it does not help as page wont be refresh at all or page will keep refreshing recursively.

    Use clientListener on the page load event
    <af:document id=”d1″>
        <af:serverListener type=”onloadEvent”
                           method=”#{<managedbean name>.<method name>}”/>
        <af:clientListener method=”onLoadClient” type=”load”/>
        <af:resource type=”javascript”>
        function onLoadClient(event) {
          AdfCustomEvent.queue(event.getSource(),”onloadEvent”,{},false);
          return true;
        </af:resource>

  • DoFilter() method is being called only at the second request

    Hi,
    I have implemented a simple Filter class
    Here is the code
    public class BasicFilter implements Filter
    FilterConfig config;
    public void init(FilterConfig config)
    System.out.println("Filter Initialised");
    this.config = config;
    public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws ServletException,
    IOException
    System.out.println("In The doFilter() method");
    ServletContext sc = config.getServletContext();
    sc.setAttribute("Hello","Hell");
    chain.doFilter(request,response);
    public void destroy()
    System.out.println("In the destroy method");
    and a simple servlet
    public class FilteredServlet extends HttpServlet
    public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<HTML>");
    out.println("<HEAD><TITLE>Filter Demo</TITLE></HEAD>");
    out.println("<BODY>");
    out.println(getServletContext().getAttribute("Hello"));
    out.println("</BODY>");
    out.println("</HTML>");
    Now when i start the server (Tomcat 4.0) i find that the filter's init() method is being called which is fine. But when i request the servlet (FilteredServlet) the doFilter() method is not called and only when i "refresh" it or call it a second time that the doFilter() method is actually called. What could be the reason for this.
    Help will be greatly appreciated.
    Thank You,
    Phani Kanuri

    Hi jleech,
    Thanks for the reply. But deleting all the temporary internet files as also the history files does not seem to have an effect. the doFilter is being called only at the second request. or did i miss anything??
    Please help. unable to complete the assignment because of this.
    Thank You,
    Phani Kanuri

  • How to call a method in jsf after stop typing in test box?

    Hi all,
    In my jsf page i have a text box in which user type some text field like "abc". i want after stop the typing i want a method to be called automatically and a datatable will be populated sith some result. my problem is is how to call the method automatically so that the user does not have to click any button after typing in the text box? plz help..
    Edited by: sailajoy on Dec 23, 2008 3:36 PM

    If it is after certain characters that the user types you can ascertain that the entry is done you can use onkeyup and within the javascript count the characters an when the necessary characters are set do the action you need to do.
    There should be some way by which you can suggest that the user has stopped typing i.e. either the max length has reached or the user has hit tab or went to another field. Going on other field too you can bring the focus back to your original field from where the user had hit tab. If you are thinking of something liek google suggest then AJAX is the best way to implement it.

  • Call method after closing JFrame

    Hi everyone,
    I'm opening a JFrame in another JFrame.
    Here is the code and beneath is the question.
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.util.*;
    public class ContactsInterface extends JFrame implements ActionListener
         JList contactList;
         private DefaultListModel listModel;
         JPanel buttonPanel;
         JPanel detailsPanel;
         JButton addButton, updateButton, deleteButton, refreshButton;
         JLabel companyLabel;
         JTextField companyField;
         public ContactsInterface()
              super("ContactList");
              listModel = new DefaultListModel();
              contactList = new JList(listModel);
              buttonPanel = new JPanel();
              detailsPanel = new JPanel();
              addButton = new JButton("Add Record");
              addButton.addActionListener(this);
              updateButton = new JButton("Update Record");
              updateButton.addActionListener(this);
              deleteButton = new JButton("Delete Record");
              deleteButton.addActionListener(this);
              refreshButton = new JButton("Refresh");
              refreshButton.addActionListener(this);
              companyLabel = new JLabel(" Company:");
              companyField = new JTextField(10);
              companyField.setEditable(false);
              buttonPanel.setLayout(new FlowLayout());
              detailsPanel.setLayout(new GridLayout(6,2,10,10));
              buttonPanel.add(addButton);
              buttonPanel.add(updateButton);
              buttonPanel.add(deleteButton);
              buttonPanel.add(refreshButton);
              detailsPanel.add(companyLabel);
              detailsPanel.add(companyField);
              setLayout(new BorderLayout());
              JScrollPane contactJScroll = new JScrollPane();
              contactJScroll.setPreferredSize(new Dimension(100,80));
              contactJScroll.getViewport().setView(contactList);
              add(contactJScroll, BorderLayout.WEST);
              add(buttonPanel, BorderLayout.SOUTH);
              add(detailsPanel, BorderLayout.CENTER);
         public void actionPerformed(ActionEvent e)
              String args = e.getActionCommand();
              if(args.equals("Add Record"))
                   openAddRecord();
         public static void main(String args[])   //main method of the ContactsInterface
              ContactsInterface CInterface = new ContactsInterface();
              CInterface.setJMenuBar(CInterface.createMenuBar());
              CInterface.setDefaultCloseOperation(EXIT_ON_CLOSE);
              CInterface.setSize(500,300);
              CInterface.setVisible(true);
              CInterface.setResizable(false);
         public void openAddRecord() // The method being called when clicking Add record which in turn opens another JFrame on top of the ContactsInterface  JFrame
              record = new AddRecord();
              record.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
              record.setVisible(true);
              record.setResizable(false);
              record.setSize(400,300);
         public void refreshList(String company)  //The method that needs to be called when disposing of the openAddRecord JFrame
              listModel.addElement(company);
              int index;
              index = contactList.getLastVisibleIndex();
              index++;
              contactList.setSelectedIndex(index);
              contactList.ensureIndexIsVisible(index);
         }The "openAddRecord Frame" opens fine, in the "openAddRecord JFrame" I add a company name.
    How can I when I click on the "Save" button in the "openAddRecord JFrame" and then dispose(); of the "openAddRecord JFrame" let it call a method in the "ContactsInterface JFrame" which was the parent of "openAddRecord JFrame" / were the "openAddRecord JFrame" was opened in, to refresh the JList by calling the "refreshList" method.

    Don't use multiple JFrames.
    A typical application will only ever have a single JFrame. If you need a second window you would use a JDialog. If you want to stop execution until the dialog is closed then you would use a "modal" JDialog.

  • How to Use Methods AFTER Work Item Execution (Modal Call)

    Hi,
    Need to execute a piece of code after a decision based on the result.
    Hope this can be done using Methods After WorkItem Execution
    Can anyone give some idea about how to use this.
    Regards
    Imman

    Hi Mike,
    I have a common piece of code that has to get executed irrespective of the decision made,but after the decision.
    Imman

  • Calling a method in ABAP OO via -

    Hi,
    I've seen that there are two ways to call a method (correct me if I'm wrong):
    the first is by using CALL METHOD
    the second is by using object->method( )
    Whenever possible (ie. the parameters are only of Returning and Importing type) I prefer the second method a lot because it's more compact and Java-style.
    Now I've faced the problem of getting the value of a context attribute.
    Can you explain to me why this piece of code works:
      DATA lo_nd_view_settings TYPE REF TO if_wd_context_node.
      DATA lo_el_view_settings TYPE REF TO if_wd_context_element.
      lo_nd_view_settings = wd_context->get_child_node( name = wd_this->wdctx_view_settings ).
      lo_el_view_settings = lo_nd_view_settings->get_element( ).
    and this, instead, it doesn't work:
      DATA lo_nd_view_settings TYPE REF TO if_wd_context_node.
      lo_nd_view_settings = wd_context->get_child_node( name = wd_this->wdctx_view_settings )->get_element( ).
    I get this error:
    Web Dynpro Comp. / Intf. ZPM_TEST_ABAP_WDP,Web Dynpro View MAIN     11     @0A\QError@
    "= ..." expected after ")->GET_ELEMENT("          
    I mean, get_child_node returns an IF_WD_CONTEXT_NODE type object who has the method GET_ELEMENT.
    So why it doesn't work?
    Thank you,
    Pietro

    Hi Pietro,
    DATA lo_nd_view_settings TYPE REF TO if_wd_context_node.
      lo_nd_view_settings = wd_context->get_child_node( name = wd_this->wdctx_view_settings
    in above statements
    1st statement indicates , you are defining a node with name  lo_nd_view_settings  ( type ref to if_wd_ context_node ).
    2nd stement indicates, the node (lo_nd_view_settings) referred to node in your context.
    in simple node is nothing but internal table,
    now if you want to read first line of table,  u have to use ge_element () method.
    so element = lo_nd_view_settings->get_element ( ).
    here lo_nd_view_Settings refer to wd_context_node, it has a method, get_element. here it will return the values of view_settings node.
    get_element ( ). will return the values of type if_wd_context_element not context_node.
    Regards
    Srinivas
    Edited by: sanasrinivas on Dec 7, 2011 10:57 AM

  • Calls to methods in a class that extends Thread

    Hello,
    I have some code that I am initiating from within an ActionListener that is part of my programs GUI. The code is quite long winded, at least in terms of how long it takes to perform. The code runs nicely, however once it is running the GUI freezes completely until operations have completed. This is unacceptable as the code can take up to hours to complete. After posting a message on this forum in regard to the freezing of the GUI it was kindly suggested that I use multi-threading to avoid the unwelcome program behaviour.
    The code to my class is as follows:
    public class FullURLAddress
      private boolean success_flag = true;
      private BufferedReader iN;
      private Document dT;
      private EditorKit kT;
      private Element lmNt;
      private ElementIterator lmIterate;
      private XURL[] compAddress;
      private int countX = 0;           //Tracks Vector vT's size.
      private int countY = 0;           //Tracks Vector vS's size.
      private int xURLcount = 0;        //Tracks XURL objects instantiated by this FullURLAddress object.
      private SimpleAttributeSet simpAtSet;
      private String aURL;              //Contains original (Xtended) URL!
      private String fileType;
      private String indexContent;
      private String[] parseURL;
      private String[] finalStrings;
      private String[] sortStrings;
      private URL indexConnect;
      private URLConnection iconn;
      private Vector vT;            //Stores href information, from targeted URL's HTML souce code.
      private Vector vS;            //Stores sorted HREF info ".jpg" and ".gif" only (no: png, tiff, etc).
      public FullURLAddress(String aURL)
        this.aURL = aURL;
        try{
          indexConnect = new URL(aURL);
          iconn = indexConnect.openConnection();
          iN = new BufferedReader(new InputStreamReader(iconn.getInputStream()));
            /* Document creation, analysis objects instantiated */
          vT = new Vector();
          vS = new Vector();
          kT = new HTMLEditorKit();
          dT = kT.createDefaultDocument();
          dT.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
            /* Iterate through document and store all HREF values */
          kT.read(iN, dT, 0);
          lmIterate = new ElementIterator(dT);
          while((lmNt = lmIterate.next()) != null)
            simpAtSet = (SimpleAttributeSet)lmNt.getAttributes().getAttribute(HTML.Tag.A);
            if(simpAtSet != null)         //As long as there are A tags to be read...
              vT.addElement(simpAtSet.getAttribute(HTML.Attribute.HREF));
              countX++;//Tracks number of HREF occurences occur, giving better control of the Vector.
        }catch(MalformedURLException e){
          success_flag = false;
          System.out.println("FullURLAddress object has encountered a "+
                             "MalformedURLException at: "+aURL);
        }catch(IOException e){
          e.getMessage();
          success_flag = false;
        }catch(BadLocationException e){
          e.getMessage();
          success_flag = false;
        /* Searches through all HREF attributes that are now stored in Vector
           vT for occurences of the character string ".htm" */
        sortStrings = new String[countX];
        for(int i=0;i<countX;i++)
          sortStrings[i] = (String)vT.elementAt(i); //Vector Strings transfered into array.
          if(sortStrings.endsWith("gif")) // Does href value end with ".jpg"?
    vS.addElement(sortStrings[i]); // If so add it to the sorted Vector vS.
    countY++;
    if(sortStrings[i].endsWith("GIF"))
    vS.addElement(sortStrings[i]);
    countY++;
    if(sortStrings[i].endsWith("jpg")) // Does href value end with ".jpg"?
    vS.addElement(sortStrings[i]); // If so add it to the sorted Vector vS.
    countY++;
    if(sortStrings[i].endsWith("JPG"))
    vS.addElement(sortStrings[i]);
    countY++;
    finalStrings = new String[countY];
    for(int j=0;j<countY;j++)
    finalStrings[j] = (String)vS.elementAt(j);
    public int getCount()
    return countY; //Returns number of instances of htm strings
    } //ending with either "jpg" or "gif".
    public String[] xurlAddressDetails()
    return finalStrings;
    I have changed the above code to make use of multithreading by making this class extend Thread and implementing the run() method as follows:
    public class FullURLAddress extends Thread
      private boolean success_flag = true;
      private BufferedReader iN;
      private Document dT;
      private EditorKit kT;
      private Element lmNt;
      private ElementIterator lmIterate;
      private XURL[] compAddress;
      private int countX = 0;           //Tracks Vector vT's size.
      private int countY = 0;           //Tracks Vector vS's size.
      private int xURLcount = 0;        //Tracks XURL objects instantiated by this FullURLAddress object.
      private SimpleAttributeSet simpAtSet;
      private String aURL;              //Contains original (Xtended) URL!
      private String fileType;
      private String indexContent;
      private String[] parseURL;
      private String[] finalStrings;
      private String[] sortStrings;
      private URL indexConnect;
      private URLConnection iconn;
      private Vector vT;            //Stores href information, from targeted URL's HTML souce code.
      private Vector vS;            //Stores sorted HREF info ".jpg" and ".gif" only (no: png, tiff, etc).
      public FullURLAddress(String aURL)
        this.aURL = aURL;
      public void run()
        try{
          indexConnect = new URL(aURL);
          iconn = indexConnect.openConnection();
          iN = new BufferedReader(new InputStreamReader(iconn.getInputStream()));
            /* Document creation, analysis objects instantiated */
          vT = new Vector();
          vS = new Vector();
          kT = new HTMLEditorKit();
          dT = kT.createDefaultDocument();
          dT.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
            /* Iterate through document and store all HREF values */
          kT.read(iN, dT, 0);
          lmIterate = new ElementIterator(dT);
          while((lmNt = lmIterate.next()) != null)
            simpAtSet = (SimpleAttributeSet)lmNt.getAttributes().getAttribute(HTML.Tag.A);
            if(simpAtSet != null)         //As long as there are A tags to be read...
              vT.addElement(simpAtSet.getAttribute(HTML.Attribute.HREF));
              countX++;//Tracks number of HREF occurences occur, giving better control of the Vector.
        }catch(MalformedURLException e){
          success_flag = false;
          System.out.println("FullURLAddress object has encountered a "+
                             "MalformedURLException at: "+aURL);
        }catch(IOException e){
          e.getMessage();
          success_flag = false;
        }catch(BadLocationException e){
          e.getMessage();
          success_flag = false;
        /* Searches through all HREF attributes that are now stored in Vector
           vT for occurences of the character string ".htm" */
        sortStrings = new String[countX];
        for(int i=0;i<countX;i++)
          sortStrings[i] = (String)vT.elementAt(i); //Vector Strings transfered into array.
          if(sortStrings.endsWith("gif")) // Does href value end with ".jpg"?
    vS.addElement(sortStrings[i]); // If so add it to the sorted Vector vS.
    countY++;
    if(sortStrings[i].endsWith("GIF"))
    vS.addElement(sortStrings[i]);
    countY++;
    if(sortStrings[i].endsWith("jpg")) // Does href value end with ".jpg"?
    vS.addElement(sortStrings[i]); // If so add it to the sorted Vector vS.
    countY++;
    if(sortStrings[i].endsWith("JPG"))
    vS.addElement(sortStrings[i]);
    countY++;
    finalStrings = new String[countY];
    for(int j=0;j<countY;j++)
    finalStrings[j] = (String)vS.elementAt(j);
    /* What happens with these methods, will they need to have their
    own treads also? */
    public int getCount()
    return countY; //Returns number of instances of htm strings
    } //ending with either "jpg" or "gif".
    public String[] xurlAddressDetails()
    return finalStrings;
    Are there any special things that I need to do in regard to the variables returned by the getCount() and xurlAddressDetails() methods. These methods are called by the code that started the run method from within my GUI. I don't understand which thread these methods are running in, obviously there is an AWT thread for my GUI and then a seperate thread for my FullURLAddress objects, but does this new thread also encompass the getCount() and xurlAddressDetails() methods?
    Please explain.
    This probably sounds a little wack, but I don't understand what thread is responisble for the methods in my FullURLAddress class aside of course from the run() method which is obvious. Any help will be awesome.
    Thanks
    Davo

    Threads are part of code that allows you to run multiple operations "simultaneously". "Simultaneously", because threads are not run actually simultaneously in any one-CPU machine. Since you most propably have only one CPU in your system, you can only execute one CPU instruction at time. Basically this means that your CPU can handle only one java-operation at time. It does not matter if you put some code in thread and start it, it will still take up all CPU time as long as the thread runs.
    So you would need a way to let other threads run also, for that purpose thread contains a yield feature that allows you to give time for other threads to run.
    http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Thread.html#yield()
    You need to use thread's yield() method in your thread code, in a place you want to give other threads time to run. Also bear in mind that if you yield your first thread run to allow second thread to run, you also need to add yield to the second thread also. If you don't, after yielding the first thread, the second thread will eat up all CPU time until it finishes, thus meaning the rest of your first thread will be run after second thread is done.
    One good place to execute yield() is usually at the end of a loop, for example 'for' or 'while' loop. This way you prevent for example while-deadlocks.
    Here is a java thread tutorial, worthy reading:
    http://java.sun.com/docs/books/tutorial/essential/threads/

Maybe you are looking for