• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems WithThread Syncronization

 
Venkat Nagam
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gurus,
My program process 100 thousands of customer records and produces 1 output record ( each record size: 3351 bytes ) for each customer and then inserts in to Oracle.
I ran this program ( single threaded ) and it took ~35 Min.
I am trying to convert in to multi threaded so that 1st thread process customer records and 2nd thread takes care of insertion in to database.
I tried following methods.
Method 1. 1st thread write in to Vector ( which is multi thread safe ) and 2nd thread reads from Vector
Method 2. 1st thread hold a lock on semaphore and then write in to String, 2nd thread keep checking String status and when it is full ( length =3351 bytes ) then copy it in to temporay string, unlocks semaphore and then inserts temporary string in to Database.
Problems with Method1 : 2nd thread reads premature data from Vector. 1st thread writes string of 3351 bytes of length and 2nd thread reads some times 0 bytes and couple bytes some times......I made write/read funcation as syncronized function, but no luck...
Problems with Method2: Works good, but it takes ~35 min, performance same as single threaded application, some time little bit worse than single threaded one. :-(
Gurus, pl suggest me what's wrong going here. Can some one suggest any better sync methords?
Thanks. :roll:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic