aspose file tools*
The moose likes Java in General and the fly likes Thread that gets the value from 3 Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Thread that gets the value from 3 Threads" Watch "Thread that gets the value from 3 Threads" New topic
Author

Thread that gets the value from 3 Threads

Mg Oo
Greenhorn

Joined: Nov 28, 2004
Posts: 22
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

Joined: Mar 06, 2006
Posts: 4
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

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.


[Jess in Action][AskingGoodQuestions]
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
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...


There is no emoticon for what I am feeling!
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Thread that gets the value from 3 Threads