Skip to content

Instantly share code, notes, and snippets.

@Echocage
Created December 18, 2018 05:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Echocage/46a9c1799b8d4920182f8ed50ebd3889 to your computer and use it in GitHub Desktop.
Save Echocage/46a9c1799b8d4920182f8ed50ebd3889 to your computer and use it in GitHub Desktop.
// Java code for thread creation by extending
// the Thread class
class MultithreadingDemo extends Thread
{
public void run()
{
try
{
// Displaying the thread that is running
System.out.println ("Thread " +
Thread.currentThread().getId() +
" is running");
}
catch (Exception e)
{
// Throwing an exception
System.out.println ("Exception is caught");
}
}
}
// Main Class
public class Multithread
{
public static void main(String[] args)
{
int n = 8; // Number of threads
for (int i=0; i<8; i++)
{
MultithreadingDemo object = new MultithreadingDemo();
object.start();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment