File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Threads and Synchronization and the fly likes newbie Q on Thread Synchronization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "newbie Q on Thread Synchronization" Watch "newbie Q on Thread Synchronization" New topic

newbie Q on Thread Synchronization

Ravi Sathish
Ranch Hand

Joined: Feb 26, 2002
Posts: 131
Hi Ranchers,

I have a loop where in I create 2 threads per iteration; I synchronize these 2 threads using shared variable and synchronization method; { There's a minor glitch though that I cannot possibly determine before hand how many threads are created }

Now after these threads are executed I need to refresh a screen.... I tried couple of ways to check the synchronization nothing seems to work so far

How do I monitor these threads?

Should I create a seperate Thread(Monitor) and schedule it to run every second or so until all these threads have finished execution? Is it possibel to post soem sample code for doing this kind of stuff

for(int i=0; i<=ingestParams.length;i++)
IngestFile ingestFile =null;
IngestFileChecker ingestFileChecker=null;

//Thread 1
ingestFile =new IngestFile(ingestParams[i],client,statusIndicator,false);
//Thread 2
ingestFileChecker = new IngestFileChecker(clientFrame,client,statusIndicator,false);

Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Look into join(). Start all your threads and put them into some collection as you go. After all are started, iterate the collection and join each one.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

What is the purpose of each thread?
Ravi Sathish
Ranch Hand

Joined: Feb 26, 2002
Posts: 131
Actually the 2 threads IngestFile and IngestFileChecker are kind of overkill.

I need one file IngestFile:
It connects to a server (using Connection pooling... its legacy code)
It transfers a file to server using a proprietry protocol
Gets a status response which is displayed in the interface

I agree. Here's the link:
subject: newbie Q on Thread Synchronization
jQuery in Action, 3rd edition