0% found this document useful (0 votes)
21 views1 page

Asynchronous Number Printing Program

The document contains a Java program named NumberPrinter.java that utilizes threading to print numbers asynchronously. It defines a Printer class that implements Runnable, allowing two threads to print numbers: Thread1 prints from 1 to 10 and Thread2 prints from 90 to 100. The main method initializes and starts both threads to execute their tasks concurrently.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views1 page

Asynchronous Number Printing Program

The document contains a Java program named NumberPrinter.java that utilizes threading to print numbers asynchronously. It defines a Printer class that implements Runnable, allowing two threads to print numbers: Thread1 prints from 1 to 10 and Thread2 prints from 90 to 100. The main method initializes and starts both threads to execute their tasks concurrently.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

/*Write a threading program which uses the same method asynchronously to print the

numbers 1 to 10 using Thread1 and to print 90 to 100 using Thread2. */


Program Name: [Link]
class Printer implements Runnable {
private final int start;
private final int end;

public Printer(int start, int end) {


[Link] = start;
[Link] = end;
}

@Override
public void run() {
for (int i = start; i <= end; i++) {
[Link](i + " "); // Prints each number from start to end
}
}
}

public class NumberPrinter {


public static void main(String[] args) {
Thread t1 = new Thread(new Printer(1, 10)); // Creates Thread1 to print numbers 1 to 10
Thread t2 = new Thread(new Printer(90, 100)); // Creates Thread2 to print numbers 90 to 100
[Link](); // Starts Thread1
[Link]();// Starts Thread2
}
}

You might also like