Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.concurrent.ForkJoinPool;
- import java.util.concurrent.TimeUnit;
- public class Main {
- public static final class randomCharThread implements Runnable{
- @Override
- public void run(){
- char achar = (char) ('A' + Math.random() * ('Z' - 'A' + 1));
- System.out.print(achar);
- }
- }
- public static final class randomDigitThread implements Runnable{
- @Override
- public void run(){
- int aDigit = (int) (Math.random() * 10);
- System.out.print(aDigit);
- }
- }
- public static final class starThread implements Runnable{
- @Override
- public void run(){
- System.out.print('*');
- }
- }
- public static void main(String[] args){
- int noOfTimes = 30;
- System.out.println("Program starts");
- final ForkJoinPool pool = ForkJoinPool.commonPool();
- for(int i=0; i<noOfTimes; i++){
- pool.execute(new randomCharThread());
- pool.execute(new randomDigitThread());
- pool.execute(new starThread());
- }
- pool.awaitQuiescence(5000, TimeUnit.MILLISECONDS);
- System.out.println("");
- System.out.println("Program ends");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement