• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

newbie Q on Thread Synchronization

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the purpose of each thread?
 
Ravi Sathish
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Warning! Way too comfortable! Do not sit! Try reading this tiny ad instead:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic