Write a program that has two threads Make the first thread a
Write a program that has two threads. Make the first thread a simple loop that continuously increments a counter and prints a period (“.”) whenever the value of that counter is divisible by 10,000,000. Make the second thread repeatedly wait for the user to input a line of text and then print “Thank you for your input.” On your system, does the first thread makes rapid progress? Does the second thread respond quickly?
Solution
Above code is easy to follow. Both the thread is using anonymous inner class and overriding run method as you can see. Both the method contain what has been asked. First contain counter variable which is incrementing and print \".\" when it is divisible by 10000000. And second method is asking user input. I have included an extra text \"Enter text\" so that user will know that computer wants input from you.
My laptop configuration is CPU Core2duo having clock speed 2.53GHz and Ram 4GB and 250GB Harddisk(decent read/write). It is running very fast and obviously it will slow down with progress. And second thread runs very fast too after entering new line(basically keyboard key \"enter\").
You can try on your system too to know the detail how fast/slow it works on your computer. And if you have any doubt you can comment.
