When to use join method

Hi,
recently i have been studying Threading, and quite fascinated by it. however i am struggling to understand in what circumstance a programmer will be using a join method on a thread.
what i understand from reading docs is, if i call join() on a thread "thread1", then whenever this call happens the "current thread" will stop its execution till "thread1" finishes its execution i.e. DIE.
when code is executing no one has control over which thread will be the current thread when the join is called.
can someone please explain with a real life scenario?
Thanks in advance

recently i have been studying Threading, and quite fascinated by it. however i am struggling to understand in what circumstance a programmer will be using a join method on a thread.
what i understand from reading docs is, if i call join() on a thread "thread1", then whenever this call happens the "current thread" will stop its execution till "thread1" finishes its execution i.e. DIE.
There are plenty of examples and documentation on the internet about multithreading and the use of 'join'.
As the doc quote suggests, and at the risk of stating the obvious, it is used when you want a thread to stop its own execution until another thread has finished its own execution.
That is a form of 'serialization' that ensures that certains steps of a process are done in a desired order.
The generic 'multi-threading' use case is that the threads can executing in parallel and have NO dependencies on each. For example, 10 threads each loading a specific file into the database.
But there are times when one process is dependent on another. Rather than bind those two processes together (e.g. by using method calls from within a single thread) a more modular approach is to launch each process in a thread but cause the second process to wait, using 'join', until the first process/thread has completed.
when code is executing no one has control over which thread will be the current thread when the join is called.
I have NO IDEA what that even means.
Again, stating the obvious, a thread can NOT execute the 'join' method unless that thread is active so if that thread is active is IS the 'current' thread. When it executes the 'join' it will be suspended until the 'joined' thread terminates. The thread that it is 'joining' may not become 'active' right away and it make take several thread rotations before it completes execution and reactivates the thread that 'joined' it.

Similar Messages

  • When we use setHeader() method??

    hi,
    when we use setHeader() method??

    Hello,
    I need to place some parameters in a header and send the others as
    a body. However when i try to place some in a header i get error.
    This is the code of the CLIENT:
    Header header=new Header();
    Vector params = new Vector ();
    params.addElement (new Parameter("UserName", String.class,
    "xxx", Constants.NS_URI_SOAP_ENC));
    (...) <-- other params (similar as the one above)
    header.setHeaderEntries(params);
    // build the call.
    Call call = new Call();
    call.setSOAPTransport(st);
    call.setSOAPMappingRegistry (smr);
    //"urn:xmethods-Temperature" (below--> for the temperature thing
    call.setTargetObjectURI("https://www.creditinform.no/creditinform
    .standardwebservice.ws2005207/InfoXML");
    call.setMethodName("HitListPerson");
    call.setEncodingStyleURI("http://schemas.xmlsoap.org/soap/encodin
    g/");
    call.setHeader(header);
    And i get the following error:
    java.lang.ClassCastException: org.apache.soap.rpc.Parameter
    at org.apache.soap.Header.marshall(Header.java:134)
    at org.apache.soap.Envelope.marshall(Envelope.java:197)
    at org.apache.soap.Envelope.marshall(Envelope.java:162)
    at
    org.apache.soap.transport.http.SOAPHTTPConnection.send(SOAPHTTPConnect
    ion.java:354)
    at org.apache.soap.rpc.Call.invoke(Call.java:261)
    Any sugestion could be helpfull.
    Thank you for your time,
    C.E.

  • How to close parent window when we use call method l_window_manager- create

    hi...
    how to close parent window when we use call method l_window_manager->create_external_window
    thank you.

    hi
    good
    go through this link,hope this ll help you to solve your problem
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/63a47dd9-0b01-0010-3d8e-de27242bf011
    thanks
    mrutyun^

  • Validations when we use GET method

    Hi Team,
    I am using GET method with the following URL(example)
    http://IP:8080/ords/schema_name/office/users/{user_id}
    URI template : office/users/{user_id}
    method:get
    source type : Feed
    Source : select * from emp where empno = :user_id;
    Using the above URL I am able to get all the specified user details in the browser.
    I want to add the validations to the service now, and response should be user defined.
    Ex : when user not in the database
    then respond with the error code and error name in JSON format ex:
    items:
    error code : 404
    message: "somthing wrong"
    I am not sure how we can achieve this functionality when we use SQL query.
    Please suggest any possible solutions for this.
    thanks
    Chandran

    grant dba_users view to apex and change the sql like this:
    select * from emp where empno = :user_id and exists (select 1 from dba_users where username=:user_id);

  • 160n halt when connected using this method

    hi there,
    I have the following scenario which cause router 160n to be down
    I have a 160n linksys router which is used as dsl router and directly connected to the internet, and I have another linksys router 160n which is connected to the first  160n router "DSL Router", and linux server (Squid & dhcp) which is also connected directly to the first 160n router " DSL router",
    the problem accurs when I turn my linux srever on, the DSL router start flashing its lights and stop working until I disconnect my server and restart the router.
    I wonder if anybody can help,
    thanks with best regards

    Make sure you have different IP for both routers and they are cascaded correctly.  Search the Linksys web site on how to cascade two routers correctly.

  • Help required in understanding when to use encodeChildren() method

    I am new to Java Server Faces. I am a little bit confused in understanding the uselfulness of encodeChildren() method in renderers? Can any one explain how a datatable component gets rendered?how is it that that row by row processing takes place?

    TableRenderer.encodeChildren() is something you can easily imagine:while(there is the next row) {
      UIData.setRowIndex(++rowIndex);
      write("<tr>");
      while(there is the next column) {
        write("<td>");
        while(there is the next component in the column) {
          nextComponent.encodeBegin();
          nextComponent.encodeChildren();
          nextComponent.encodeEnd();
        write("</td>");
      write("</tr>");
    }

  • When i used invoke methode with read out variants array byte crashd my LV by recal the second repeat?

    If i check it with VBASIC it runs fine, check it to run with Delphi its fine, wot is wrong with LV 6.02

    You may want to contact National Instruments directly. Try: www.ni.com/ask
    Brian

  • 2 Questions How to use join() and Which is best coding pratice.

    Hi All,
    I have 2 Question:
    I have a MultipleThread class and when I try to use join method of thread class I get compile time error(so i commented it out).I also wanted to know is the best approch to write a threaded program.I also wanted to know about the best coding pratice for threadand also do I need to declare Instance variable thread and name(Is it possible to create multiple thread with out declaring instance variable thread and name , if yes which one is the better way 1> with instance variable 2> with out instance variable)

    Sorry here is the code.
    package javaProg.completeReferance;
    public class MultipleThread implements Runnable
         Thread thread;
         String name;
         MultipleThread(String nam)
              this.name=nam;
              thread = new Thread(this,name);
              thread.start();
         public void run()
              try
                   for (int i=1;i<=10;i++ )
                        Thread.sleep(1000);
                        System.out.println("Thread "+name+" "+i);
              catch (InterruptedException e)
                   System.out.println(""+e);
         public static void main(String [] args)
              try
                   MultipleThread t1=new MultipleThread("One");
                   MultipleThread t2=new MultipleThread("Two");
                   MultipleThread t3 =new MultipleThread("Three");
                   //t1.join();
                   //t2.join();
                   //t3.join();
                   for (int i=1;i<=10;i++ )
                        Thread.sleep(1000);
                        System.out.println("Parent Thread "+i);
              catch (InterruptedException e)
                   System.out.println(" "+e);
    }

  • When to use "this." when not to ?

    Hi, I know this will be a basic question, but can someone tell me the rule of when to use this.method/variable/etc and when not to ?
    If I have (And I'll cut down the code,leaving construtors, etc.)
    public abstract class DataStuff
    protected String message = null;
    protected void clearMessage()
    this.message = null; // Do I use this.
    message = null; // Or not ?
    } // End clearMessage()
    } // End Class ---------
    Lets get more complicated
    public class MoreStuff extends DataStuff
    public void someMethod()
    this.message = "Do I use This ?";
    message = "Or Do I not ?";
    this.clearMessage(); // or
    clearMessage();
    } // End someMethod()
    } // End Class ------
    I know this will be fairly simple, and I am sure there are lots of Tutorials I could not find that explain the difference between "this"
    thanks
    Paul

    Besides using the this reference for instance variables that have the same name as a local variable, it is also used when your class implements an interface and uses it in the class. Let me further explain. Lets pretend that you create a JFrame that has buttons on it. You want your buttons to handle events so you add an ActionListener to the buttons. You also want to code your event handling in the JFrame so you cause your JFrame to implement the ActionListener interface and implement the required method actionPerformed() in your JFrame class. Well, when you add and actionListener to the buttons, you have to use the this reference in the method signature. See code for example.import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class ExampleJFrame extends JFrame implements ActionListener {
       public ExampleJFrame() {
          super("Example using 'this' reference!");
          Container c = getContentPane();
          JButton button = new JButton("Push Me");
          /* Here is the example of how the 'this' reference is
             used.  Since this class implements ActionListener,
             that means it is an ActionListener.  So, when
             we add the method addActionListener to the button,
             it requires that an ActionListener be put into
             the method signature.  So, I just pass a reference
             to this class into it (using the 'this' reference).
             Its actionPerformed method will be called.  There
             are 3 ways I could think of to handle the
             events for this button.  One is to do it the way
             I chose to do it; that is, have the originating
             class (ExampleJFrame) handle it.  That is where
             the 'this' reference comes into play.  Two is
             to use an anonymous inner class.  The second
             option is useful if the code is small and
             self contained.  Three is to have another
             class handle it, such as an Action. */
          button.addActionListener(this);
          c.add(button);
          /* incidentally, you could put the this keyword in
             front of each of these methods for readability,
             but most people don't. I used it on the first
             one to demonstrate it.  */
                   //cause the program to end when closing
          this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          pack();
          setVisible(true);
       }//end constructor
       /*=**************************************************
       * actionPerformed(): required ActionListener method *
       public void actionPerformed(ActionEvent e) {
          /* the this reference is also used in here because
             the showMessageDialog() should have as its
             parent a component and we want the component to
             be this JFrame */
          JOptionPane.showMessageDialog(this,"You used the this pointer!");
       }//end actionPerformed
       public static void main(String args[]) {
          /* when you run this class, a small JFrame with
             a button will appear in the top left corner. */
          ExampleJFrame app = new ExampleJFrame();
       }//end main
    }//end ExampleJFrame classtajenkins

  • Error : when i use transform

    The problem is still coming after doing an update to Oracle9i 9.2.0.2.0
    When i use transform method, It logs me out. if i do same transform using xmlspy it works.
    html := srcXml.transform(xslFile);
    return html.getclobval();
    where
    srcXml : select extract(value(x), xPath) into srcXml from tbl_main_xml x;
    xslFile : select xsldoc into xslFile from tbl_xsl
    where filename = xslFileName;
    How to open a tar to submit my xml and xsl files.
    Regards
    Error which is coming :
    SQL> select gethtml from dual;
    ERROR:
    ORA-03113: end-of-file on communication channel
    no rows selected

    Hi Mark
    I have opened a tar and submitted my xml and xsl files.
    TAR 2903047.995
    Can you pls have a look.
    Regards

  • Javascript enabling and using JS methods on TextEdit component

    Hello Friends:
    I am working to display data using TableView component.
    In each row, one of the cell contains a group of radio
    buttons and an other cell contains TextEdit component.
    For an event on the group of radio buttons, the TextEdit
    should flip editable to non-editable and vice-versa.
    I am using the TextEdit attribute method,
    <b>setJsObjectNeeded(true)</b>
    to expose the JavaScript methods of the component.
    I am using the following bits of code for accessing the
    TextEdit JavaScript functionality.
    var funcName = htmlb_formid+"_getHtmlbElementId";
    func = window[funcName];
    var text_edit_comp = eval(func(id_of_textedit));
    <b>text_edit_comp.setEnabled()</b>;
    Whole thing works as planned, but it is not possible to
    disable or enable the TextEdit component using the
    JavaScript, as shown above.
    In the portal documentation, the JavaScript object
    methods were mentioned only for certain components, NOT
    including TextEdit !!
    If I replace TextEdit with InputField, it works perfectly
    as like needed.
    How to hack it to work for TextEdit ?
    Thank you very much for your kind answers.
    Prasad Nutalapati

    I did use the suggestion. No use.
    When I say,
    var textedit = eval(func("<id-of-the-textedit-from-java"));
    I am getting the object reference.
    When I say,
    <b>var id = textedit.id;
    var elem = document.getElementById(id);</b>
    I am getting the HTML name/id and object of the text edit.
    Now when I use JS methods and properties,
    alert("type="+elem.type);
    alert("name="+elem.name);
    I get them back correctly.
    Then when I say,
    <b>alert("disable ?"+ document.forms[0].elements[elem.name].disabled;</b>
    I am getting answer as 'false' which is not correct. It
    is initially disabled, when I defined with Java.
    And subsequently, when I say,
    <b>document.forms[0].elements[elem.name].disabled = false;</b>
    It didn't affect it at all.
    If I try to use the JS methods provided by Portal, like..
    <b>textedit.setEnabled();</b>
    It is giving an JS error saying that the object doesn't
    have that method.

  • Cannot use clone() method of LinkedList...That's strange

    I got a very strange problem. I wrote the following statement:
    Integer[] nums = generateRandomIntegerArray();
    List<Integer> list = new LinkedList<Integer>(Arrays.asList(nums));
    List<Integer> clone = list.clone();
    .....I got an error statement: cannot find symbol-method clone().
    When I use other methods it's fine, but I cannot use clone().
    That's really strange. I've checked many times, clone() method does exist
    in the LinkedList class.

    Your list variaiable is to an object implementing the interface List and clone is not part of the List interface. To get to the clone method you must cast it back to LinkedList, or use a LinkedList reference.

  • I can't burn a dvd using any method, Idvd tells me that my super drive is missing, dvd studio pro quits when i click burn and disk utility keeps spitting the disk out when i click burn and enter the disk??? how do i repair my superdrive for imac

    I can't burn a dvd using any method, idvd tells me that my super drive is missing, dvd studio pro quits when i click burn and disk utility keeps spitting the disk out when I click burn and enter the disk??? how do i repair my superdrive for imac, or how do I do whatever I need to do to get it working: I have already tried using a lens cleaning cd and also restored my nvram or something i forget what it was called but i restarted my computer holding down  command+optoion+p+r and still nothing???
    Free solutions are the best, although if I have to pay I will, I would prefer to not have to buy an external burner if possible and already know that is an option so please don't give me that answer... thank you for any help you can give

    Unless your iMac is still covered by AppleCare, get an external DVD burner.
    You can get perfectly good ones from Amazon for less than $40.

  • I hit Forget Network and now cannot get back onto my wireless home network. All of my other computers and iphones are fine.  How do I get the network back?  It shows in my list of networks but when I use the password and try to join it says not connected.

    I hit Forget Network and now cannot get back onto my wireless home network. All of my other computers and iphones are fine.  How do I get the network back?  It shows in my list of networks but when I use the password and try to join it says not connected.

    See if the iPad will accept the password after you restart it. It's worth a try.
    Restart the iPad by holding down on the sleep button until the red slider appears and then slide to shut off. To power up hold the sleep button until the Apple logo appears and let go of the button.
    You could also try a reset as well.
    Reset the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons.

  • Invalid meta tag generated when using XHTML method

    Hi,
    I'm trying to generate an XHTML file using XSL and the XHTML output method. However, transformation results in adding the following XHTML-invalid meta tag (uppercase and non-closing) in the head tag:
    <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
    Is it a bug in the XDK or am I missing something? Transform is performed using the JXTransformer provided in 11g.
    Thanks in advance,
    Stephane
    input file:
    <?xml version='1.0' encoding='utf-8'?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xml:lang='en' lang='en' xmlns='http://www.w3.org/1999/xhtml'>
    <head>
         <title>Some title</title>
    </head>
    <body></body>
    </html>
    xsl file:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xhtml="http://www.w3.org/1999/xhtml">
         <xsl:output method="xhtml"
    doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
    <xsl:template match="*">
         <xsl:element name="{local-name()}" namespace="http://www.w3.org/1999/xhtml">
              <xsl:apply-templates />
         </xsl:element>
    </xsl:template>
    </xsl:stylesheet>
    output:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    *<META http-equiv="Content-Type" content="text/html; charset=UTF-8">*
    <title>Some title</title></head><body></body></html>

    For some reason when I use MapForce tool to generate my xslt mapping source, it is generating the following statement in the xsl file.
         <xsl:namespace-alias stylesheet-prefix="n" result-prefix="#default"/>
    So at the root element of XML file, it is replacing the character n with '#default' for some reason, I don;t know the purpose of this.
    As you suggested, I changed the name space, still I experienced same problem.
    It is now resolved after removing the above xsl statement from the xsl file before creating/uploading the relevant zip file into archives folder.
    It works fine now. Thanks for the clue.

Maybe you are looking for