The document discusses 5 examples of Java thread programming - extending Thread class, implementing Runnable interface, anonymous Runnable implementation, using ExecutorService for thread pool, and using Callable with Future for thread result.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
8 views
Java Assignment
The document discusses 5 examples of Java thread programming - extending Thread class, implementing Runnable interface, anonymous Runnable implementation, using ExecutorService for thread pool, and using Callable with Future for thread result.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4
JAVA ASSIGNMENT
Name: Y Sai Akhilesh
Roll no : CB.SC.U4AIE23348 Section: D 1. Extending Thread class: java public class ThreadExample extends Thread { public void run() { for (int i = 1; i <= 10; i++) { System.out.println("Thread: " + i); } }
public static void main(String[] args) {
ThreadExample thread = new ThreadExample(); thread.start(); } }
2. Implementing Runnable interface:
java public class RunnableExample implements Runnable { public void run() { for (int i = 1; i <= 10; i++) { System.out.println("Runnable: " + i); } }
public static void main(String[] args) {
Thread = new Thread(new RunnableExample()); thread.start(); } }
3. Anonymous Runnable implementation:
java public class AnonymousRunnableExample { public static void main(String[] args) { Thread thread = new Thread(new Runnable() { public void run() { for (int i = 1; i <= 10; i++) { System.out.println("Anonymous Runnable: " + i); } } }); thread.start(); } }