aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "newbie Q on Thread Synchronization" Watch "newbie Q on Thread Synchronization" New topic
Author

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

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

if(ingestParams[i]!=null)
{
//Thread 1
ingestFile =new IngestFile(ingestParams[i],client,statusIndicator,false);
ingestFile.start();
//Thread 2
ingestFileChecker = new IngestFileChecker(clientFrame,client,statusIndicator,false);
ingestFileChecker.start();
}
}
</code>

TIA
R
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

Thanks
Ravi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: newbie Q on Thread Synchronization