• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread that gets the value from 3 Threads

 
Mg Oo
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
quiz09


A Java Program uses four threads. The first three threads each read a text file
and count the number of times that a given word is used in the text file.
The words which are to be counted are provided on a command line as shown when
the execution of the program is initiated : :

java countIt hello world me


The above line shows that countIt is the program being executed.
The first thread object counts the word 'hello, the second 'world' and the
third 'me'

Each of the thread objects communicates its findings to the fourth thread object which displays the results in a JTextArea as below : :

hello 4
world 9
me 3

Note that the words appear in alphabetical order.

---------------------------------------------------
For the above quizz, I've created a wordcount class.

Still I was confused : :
For the three thread, each thread use the same function or different ?

I think I have to synchronize three threads and then pass the values to the fourth thread ? or make the fourth thread monitar the value passed ?


Any ideas ?

Thank you so much.
 
Ravi Kumaar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the same function in all the threads.

Regarding synchronization : As long as you dont use any resource that is shared among the threads, you dont need to synchronize.

Why do you need the fourth thread. You can update the text area using SwingUtilities.invokeLater within the first 3 threads.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mg --

You've already been asked to comply with the naming policy. If you want to be able to continue visiting the Ranch, please do so immediately.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you googled for "Mg Mg Oo" or "Mg Oo"? It seems to be a Burmese name, and there is a Dr. Mg Mg Oo as well as a Web Designer Mg Oo out there in cyberspace...
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeff Albertson:
Have you googled for "Mg Mg Oo" or "Mg Oo"?


Hmm. OK, well, still, Mr. Mg Oo ignored the last request, and has so far ignored this one. I'd like to hear "But that's my real name!" from himself, if possible.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic