Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.concurrent.ForkJoinPool;
  4. import java.util.concurrent.TimeUnit;
  5.  
  6. public class Main {
  7. public static final class randomCharThread implements Runnable{
  8. @Override
  9. public void run(){
  10. char achar = (char) ('A' + Math.random() * ('Z' - 'A' + 1));
  11. System.out.print(achar);
  12. }
  13. }
  14. public static final class randomDigitThread implements Runnable{
  15. @Override
  16. public void run(){
  17. int aDigit = (int) (Math.random() * 10);
  18. System.out.print(aDigit);
  19. }
  20. }
  21. public static final class starThread implements Runnable{
  22. @Override
  23. public void run(){
  24. System.out.print('*');
  25. }
  26. }
  27. public static void main(String[] args){
  28. int noOfTimes = 30;
  29. System.out.println("Program starts");
  30. final ForkJoinPool pool = ForkJoinPool.commonPool();
  31. for(int i=0; i<noOfTimes; i++){
  32. pool.execute(new randomCharThread());
  33. pool.execute(new randomDigitThread());
  34. pool.execute(new starThread());
  35. }
  36. pool.awaitQuiescence(5000, TimeUnit.MILLISECONDS);
  37. System.out.println("");
  38. System.out.println("Program ends");
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement