Note that there are some explanatory texts on larger screens.

plurals
  1. POinterfere threads
    primarykey
    data
    text
    <p>I have a problem with understanding this code , My question is why the two threads does not interfere with each other during executing the statements in <code>run</code> method ?</p> <p>I mean that always a thead do all statements then come second thread to do statements.</p> <p>it is impossible that first thread do portion of statements then second thread do portion of statements then first thread continue its task .............</p> <p>note : I know that the two threads uses different <code>OutputStream</code> object</p> <p>Thread code here</p> <pre><code>class Printer extends Thread { private String ThreadName; public Printer(String name) { this.ThreadName=name; } public void run() { PrintStream out=new PrintStream(System.out); out.println(this.ThreadName+" : a"); out.println(this.ThreadName+" : b"); out.println(this.ThreadName+" : c"); out.println(this.ThreadName+" : d"); out.println(this.ThreadName+" : e"); out.println(this.ThreadName+" : f"); out.println(this.ThreadName+" : g"); out.println(this.ThreadName+" : h"); out.println(this.ThreadName+" : i"); out.println(this.ThreadName+" : j"); out.println(this.ThreadName+" : k"); } } </code></pre> <p>Entry Code:</p> <pre><code>class Main { public static void main(String[] args) { Thread t1 = new Printer("thread 1"); Thread t2 = new Printer("thread 2"); t1.start(); t2.start(); } } </code></pre> <p>try to replace <code>System.out</code> with <code>out</code> and compare the results then you will know exactly what am I asking for </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload