Java program to print a string in distributed manner


Question:

Java program to print a string in distributed manner

Design a Java "Hello World" program that should mimic distributed processing of printing the string "Hello World!" on display.

For doing this the main() method should just create 5 threads and store references to them in an array of threads, which will be passed to each thread for communication purposes. Then the main() method should start all threads, wait for their completion and exit. It must not control the threads in any way or send any other information to them.

Each thread will compete for the display access and once it is granted, the thread prints out only one character of the string (namely the next one in order) and then starts to compete for the display access again for printing the next character. If all characters of the string are printed, the thread exits. This way each of the threads will execute the same algorithm and print just a few string characters.

Printing a string character can be considered as a critical part of the thread code. For this, implement a mechanism providing mutual exclusion, but without using any synchronization approaches (semaphores, locks, etc.). Each of the threads should be able to communicate with other threads by sending messages to them. The communication must be purely distributed in the sense that no other shared object is available to threads besides of the Thread array workers.

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Java program to print a string in distributed manner
Reference No:- TGS01937749

Now Priced at $20 (50% Discount)

Recommended (97%)

Rated (4.9/5)