<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>java multi threading Archives -</title>
	<atom:link href="https://mitindia.in/tag/java-multi-threading/feed/" rel="self" type="application/rss+xml" />
	<link>https://mitindia.in/tag/java-multi-threading/</link>
	<description></description>
	<lastBuildDate>Sat, 09 Jul 2016 07:49:46 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://mitindia.in/wp-content/uploads/2023/03/cropped-android-chrome-512x512-1-32x32.png</url>
	<title>java multi threading Archives -</title>
	<link>https://mitindia.in/tag/java-multi-threading/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Java Multi Thread Example</title>
		<link>https://mitindia.in/java-multi-thread-example/</link>
		
		<dc:creator><![CDATA[SKB]]></dc:creator>
		<pubDate>Thu, 30 Jun 2016 08:41:59 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[java multi threading]]></category>
		<guid isPermaLink="false">http://www.mitindia.in/?p=209</guid>

					<description><![CDATA[<p>Java Program to show Multi Threading class Ta extends Thread { public void run() { for(int i=1; i&#60;=5; i++) { System.out.println("A thread=" + i); } System.out.println("Ta is over"); } } class Tb extends Thread { public void run() { for(int j=1; j&#60;=5; j++) { System.out.println("B thread=" + j); } System.out.println("Tb is over"); } } class [&#8230;]</p>
<p>The post <a href="https://mitindia.in/java-multi-thread-example/">Java Multi Thread Example</a> appeared first on <a href="https://mitindia.in"></a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Java Program to show Multi Threading</p>
<pre>class Ta extends Thread
{
public void run()
{
for(int i=1; i&lt;=5; i++)
{
System.out.println("A thread=" + i);
}
System.out.println("Ta is over");
}
}

class Tb extends Thread
{
public void run()
{
for(int j=1; j&lt;=5; j++)
{
System.out.println("B thread=" + j);
}
System.out.println("Tb is over");
}
}

class thread
{
public static void main(String args[])
{
Ta ta=new Ta();
ta.start();

Tb tb=new Tb();
tb.start();
}
}</pre>
<p>Java Threading program to show use of stop() method</p>
<pre>class Ta extends Thread
{
public void run()
{
    for(int i=1; i&lt;=5; i++)
    {
    try 
    { 
    sleep(1000);
    }
    
    catch(Exception e) {}

System.out.println("Thread A= " + i);
}
System.out.println("Exit of Thread A");
}
}

class Tb extends Thread
{
public void run()
{
    for(int j=1; j&lt;=5; j++)
    {
    if (j==3) 
    stop();
    System.out.println("Thread B= " + j);

    }
}
}

class thread2
{
public static void main(String args[])
{
Ta ta=new Ta();
ta.start();
Tb tb=new Tb();
tb.start();
}
}</pre>
<p>Java Program to demonstrate Multi threading.</p>
<pre>class Ta extends Thread
{
public void run()
{
    for (int i=1; i&lt;=5; i++)
    {
    try
    {
    sleep(1000); 
    }
    catch(Exception e) {}

    System.out.println("Thread A is running="+i);
    }
System.out.println("Thread A is Stopped");
}
}

class Tb extends Thread
{
public void run()
{
    for (int j=1; j&lt;=5; j++)
    {
    try
    {
    sleep(500); 
    } catch(Exception e) {}

System.out.println("Thread B is running="+j);
}
System.out.println("Thread B is Stopped");
}
}

class thread3
{
public static void main(String args[])
{
Ta ta=new Ta();
ta.start();

Tb tb=new Tb();
tb.start();
}
}</pre>
<p>Java Program to demonstrate Thread Priority (MIN and MAX Priority)</p>
<pre>class Ta extends Thread
{
public void run()
{
    for(int p=1; p&lt;=5; p++)
    {
    try
    {
    sleep(500);
    }
    catch(InterruptedException e) { } 
    System.out.println("Thread is running=p: "+p);
    }
}
}

class Tb extends Thread
{
public void run()
{
    for(int q=1; q&lt;=5; q++)
    {
    try
    {
    sleep(500);
    }
    catch(InterruptedException e) { } 
    System.out.println("Thread is running=q: "+q);
    }
}
}

class thread5
{
public static void main(String args[])
{
Ta ta=new Ta();
Tb tb=new Tb();

tb.setPriority(Thread.MAX_PRIORITY);
ta.setPriority(Thread.MIN_PRIORITY);

ta.start();
tb.start();

System.out.println("Main thread is stopped");
}
}</pre>
<p>Java Program to demonstrate Synchronized thread.</p>
<pre>class Tb extends Thread
{
int total;
public void run()
{
synchronized(this)
{
for(int i=0; i&lt;10; i++)
{
    try
    {
    sleep(1000); 
    }
    catch(Exception e) {}

 total += i;
}
   notify();
     }
   }
}
public class thread6 
{
public static void main(String args[])
{
Tb b = new Tb();
b.start();
synchronized(b)
{
 try
{
System.out.println("Waiting for b to complete the calculation...");
b.wait();
}
catch(InterruptedException e){}
System.out.println("Total is: " + b.total);
 }
}
}</pre>
<p>Java File handling example to show total no. of lines / strings present in the file.</p>
<pre>import java.io.*;

public class NOL
{
public static void main(String[] args) 
{
try
{
System.out.println("Getting line number of a paritcular file example!");
 BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 System.out.println("Please enter file name with extension:");
   String str = bf.readLine();
   File file = new File(str);
   if (file.exists())
{
    FileReader fr = new FileReader(file);
   LineNumberReader ln = new LineNumberReader(fr);
  int count = 0;
  while (ln.readLine() != null){
 count++;
  }
  System.out.println("Total line no: " + count);
 ln.close();
  }
 else{
  System.out.println("File does not exists!");
  }
 }
 catch(IOException e){
 e.printStackTrace();
 }
 }
}</pre>
<div>
<p>Java Program to show Random Numbers</p>
<pre>import java.util.*;

public class rannum
{
public static void main(String[] args)
{
  Random rand = new Random();

  int num = rand.nextInt(20);
  System.out.println("Generated Random Number between 0 to 20 is : " + num);

  int numNoRange = rand.nextInt();
  System.out.println("Generated Random Number without specifying any range is : " + numNoRange);
}
}</pre>
</div>
<p><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=https%3A%2F%2Fmitindia.in%2Fjava-multi-thread-example%2F&amp;linkname=Java%20Multi%20Thread%20Example" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fmitindia.in%2Fjava-multi-thread-example%2F&amp;linkname=Java%20Multi%20Thread%20Example" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fmitindia.in%2Fjava-multi-thread-example%2F&#038;title=Java%20Multi%20Thread%20Example" data-a2a-url="https://mitindia.in/java-multi-thread-example/" data-a2a-title="Java Multi Thread Example"><img src="https://static.addtoany.com/buttons/favicon.png" alt="Share"></a></p><p>The post <a href="https://mitindia.in/java-multi-thread-example/">Java Multi Thread Example</a> appeared first on <a href="https://mitindia.in"></a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
