Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Java code for thread creation by implementing
- // the Runnable Interface
- class MultithreadingDemo implements Runnable {
- public void run() {
- try {
- // Displaying the thread that is running
- System.out.println(
- "Thread " + Thread.currentThread()
- + " is running");
- } catch (Exception e) {
- // Throwing an exception
- System.out.println("Exception is caught");
- }
- }
- }
- // Main Class
- class Multithread {
- public static void main(String[] args) {
- int n = 8; // Number of threads
- for (int i = 0; i < n; i++) {
- Thread object = new Thread(new MultithreadingDemo());
- object.start();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement