Advertisement
Alice_Kim

50_threads

Jun 1st, 2020
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. public class MyThread extends Thread {
  2.  
  3. @Override
  4. public void run() {
  5. System.out.println(Thread.currentThread().getName());
  6. try {
  7. Thread.sleep(100);
  8. } catch (InterruptedException e) {
  9. System.out.println("Thread has been interrupted.");
  10. }
  11. }
  12.  
  13. public static void main(String[] args) {
  14. for (int i = 0; i < 50; i++) {
  15. MyThread myThread = new MyThread();
  16. myThread.setName(String.valueOf(i + 1));
  17. myThread.start();
  18. }
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement