multithreading - Running multiple threads concurrently in java -
i have run 2 threads concurrently 1 prints numbers 1 500 whereas prints numbers 501 1000. output must show concurrency.
try below code. main thread prints numbers 1 500 , other thread prints there on 1000.
public class test implements runnable{ public static void main(string[] args) throws exception { thread t = new thread(new test()); t.start(); (int = 1 ; <=500 ; i++) system.out.println("main thread printing "+i); } @override public void run() { (int i=501; <=1000 ; i++) system.out.println("thread 1 printing "+i); } }
Comments
Post a Comment