Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

newbie Q on Thread Synchronization

 
Ravi Sathish
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the purpose of each thread?
 
Ravi Sathish
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic